/*******************************************************************************
 * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved.
 * @file     bsp.c
 * @author   UartTFT Application Team
 * @version  V0.0.1
 * @date     2023-01-11
 * @brief    This file provides UartTFT Application display function
 ********************************************************************************/

#include "bsp.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "bsp_user.h"
#include "pit.h"
#include "tp_ctp.h"
#include "tp_rtp.h"
#include "iic.h"
#include "data.h"
#include "wav_dac.h"
#include "reset_drv.h"
#include "levetop.h"
#include "function_drv.h"
#include "uart_update.h"
#include "sincos_table.h"
#include "eflash_drv.h"


uint8_t W_buff[WR_SIZE];

uint32_t Display_Layer = 0;
uint8_t Flash_type = 1;

/*configuration parameter variable*/
uint8_t buzzer = 0;
uint16_t Start_page = 0;
uint8_t SCI_C0 = 0x5A;
uint8_t SCI_C1 = 0xA5;
uint8_t CRC_Enable_Flag = 1;
uint8_t CRC_Feedback_Flag = 1;
uint8_t Screen_DIR = 0;
uint8_t TFT_bitcolor = 0;
uint8_t parity_flag = 0;
uint8_t multi_language = 0;
uint8_t multi_language_count = 0;
//uint16_t Mode_I_Sum = 0;     

uint8_t UI_update = 0;

/*ModBus operating variables*/
uint16_t Cnt_ModbusTX = 0; // record the offset position of Modbus operation parameters
uint16_t Sum_ModbusTX = 0; // total length of Modbus operation parameters

/*picture information*/
uint16_t pic_id = 0;
uint16_t pic_id_popup = 0;   //for pop-up
uint16_t pic_id_temp = 0;    //for keyboard
uint32_t pic_add = 0;
uint16_t pic_w = 0;
uint16_t pic_h = 0;
uint32_t pic_len = 0;
uint8_t pic_flag = 0;

/*backlight information*/
//#if (LT269_SCREEN != 2)
uint16_t gDutyBuf[64] = {0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160, 168, 176, 184, 192,
						 200, 208, 216, 224, 232, 240, 248, 256, 264, 272, 280, 288, 296, 304, 312, 320, 328, 336, 344, 352, 360, 368, 376, 384, 392,
						 400, 408, 416, 424, 432, 440, 448, 456, 464, 472, 480, 488, 496, 500};
//#else
//uint16_t gDutyBuf[64] = {500, 496, 488, 480, 472, 464, 456, 448, 440, 432, 424, 416, 408, 400,
//						 392, 384, 376, 368, 360, 352, 344, 336, 328, 320, 312, 304, 296, 288, 280, 272, 264, 256, 248, 240, 232, 224, 216, 208, 200,
//						 192, 184, 176, 168, 160, 152, 144, 136, 128, 120, 112, 104, 96, 88, 80, 72, 64, 56, 48, 40, 32, 24, 16, 8, 0};
//#endif
						 
//uint8_t gDutyflag = 0;
uint8_t Auto_Backlight = 0;
//uint8_t Backlight_On = 0;
//uint8_t Backlight_Off = 0;
//uint16_t Backlight_time = 0;
uint32_t Backlight_count = 0;
uint8_t Backlight_flag = 0;
//uint8_t Backlight_first_touch = 0;
uint8_t Backlight_touch = 0;

/*Variable space*/
//uint8_t var[VAR_SIZE] = {0};				    // variable buffer(reserved)
uint8_t *var = (uint8_t *)(0x1FFF8000);			// variable buffer
uint8_t var_temp[VAR_SIZE] = {0};				// variable buffer
uint8_t config_buff[PAGECFG_SIZE] = {0};		// variable buffer
uint8_t Display_buff[STRLEN_SIZE];				// display buffer
uint8_t Display_buff_temp[STRLEN_SIZE];			// display buffer
uint16_t Curve_buff[CURVE_SIZE][1024] = {0}; // Curve data buffer: 8 channels, 16KB in total
uint16_t Curve_count[CURVE_SIZE] = {0};		// Curve length
uint8_t curve_update_flag[CURVE_SIZE];		// Curve update flag
Curve_Info gCurve_Info[CURVE_SIZE];

/*data display*/
uint8_t data_D_num = 0;					 // width used to recorddata display
uint16_t data_D_w[DATA_WLEN_SIZE] = {0}; // width used to recorddata display
uint16_t data_w = 0;

/*picture data display*/
uint8_t pdata_D_num;					   // width used to record picture data display
uint16_t pdata_D_w[PDATA_WLEN_SIZE] = {0}; // width used to record picture data display

/*encoder*/
uint16_t gEncoder_addr[40] = {0};
uint16_t Check_box_add = 0xFFFF;
uint8_t Check_box_flag = 0;
uint8_t gEncoder_count = 0;
uint8_t gEncoder_num = 0;
uint8_t knob_flag = 0;
uint8_t gEncoderFlag = 0;

/*touch public*/
uint8_t button_Press_flag = 0; // other touch cannot act after the touch is pressed
uint8_t buzzer_start = 0;
uint8_t buzzer_10ms_count = 0;
uint8_t Button_Key_Code_Flag = 0;
uint16_t Button_Key_Code = 0;

/*basic touch*/
uint8_t Basci_count = 0;
uint8_t Basci_flag = 0;
uint8_t Basci_num = 0;
Basci_Info gBasci_Info[BASIC_SIZE];

/*variable adjustment*/
uint8_t Adj_count = 0;
uint8_t Adj_flag = 0;
uint8_t Adj_num = 0;
uint8_t Adj_time = 0;
uint8_t Adj_loop = 0;
Adj_Info gAdj_Info[ADJUST_SIZE];

/*sliding progress bar*/
uint8_t Slide_count = 0;
uint8_t Slide_flag = 0;
uint8_t slide_first_touch = 0;
uint8_t slide_num = 0;
Slide_Info gSlide_Info[SLIDE_SIZE];

/*data keyboard*/
Dio_Info gDio_Info[DIO_SIZE];
uint8_t Dio_count = 0;
uint8_t Dio_num = 0;
uint8_t Dio_flag = 0;

/*keyboard keys*/
Kb_Info gKb_Info[KEYBOARD_SIZE];
uint8_t Kb_count = 0;
uint8_t Kb_num = 0;
uint8_t Kb_flag = 0;
uint8_t DioKb_flag = 0; // data input flag
uint8_t dot_flag;
uint8_t i_len = 0;
uint8_t d_len = 0;
uint16_t input_len = 0;
uint8_t neg_flag = 0;
uint16_t input_w = 0;
uint8_t cur_w = 0; // cursor width
uint16_t cur_x = 0;
uint16_t cur_y = 0;
uint16_t Cusor_time = 0; // cursor blink time
uint8_t Cusor_sw = 0;

/*sliding gesture*/
Gesture_Info gGesture_Info;


/*slide_screen*/
uint8_t gFirstTouch = 0;
uint8_t Ges_sc_flag = 0;
uint16_t GeslastXY = 0;
uint16_t Gespos = 0;
uint16_t last_Gespos = 0;

/*ASCII keyboard*/
Aio_Info gAio_Info[AIO_SIZE];
uint8_t Aio_count = 0;
uint8_t Aio_num = 0;
uint8_t Aio_flag = 0;
uint8_t AioKb_flag = 0;
uint8_t CapsLock = 0; // Caps lock

/*GBK keyboard*/
GBKio_Info gGBKio_Info[GBKIO_SIZE];
uint8_t GBKio_count = 0;
uint8_t GBKio_num = 0;
uint8_t GBKio_flag = 0;
uint8_t GBKioKb_flag = 0;
uint8_t GBK_PY_length = 0; // Pinyin length
uint8_t GBK_CN_EN = 0;	   // Chinese and English input method enable
uint8_t GBK_PY_buff[8] = {0};
uint16_t GBK_PY_num = 0;
uint8_t GBK_len = 0;
uint32_t GBK_PY_addr = 0;
uint8_t GBK_linenum = 0;

/*variable control of touch mode*/
uint8_t VarKey_count = 0;
uint8_t VarKey_flag = 0;
uint8_t VarKey_num = 0;
VarKey_Info gVarKey_Info[BATCH_SIZE];

/*pop-up window*/
uint8_t Pop_up_count = 0;
uint8_t Pop_up_flag = 0;
uint8_t Pop_up_num = 0;
uint8_t Pop_up_press = 0;
uint16_t Pop_up_x = 0;
uint16_t Pop_up_y = 0;
uint16_t Pop_up_id = 0;
Pop_up_Info gPop_up_Info[POPUP_SIZE];

uint8_t Ascii_w[95] = {0};

uint8_t Gif_num = 0;
uint8_t Gif_flag = 0;
Gif_Info gGif_Info[GIF_SIZE];

const uint32_t CRC32_Table[256] = {
	0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419,
	0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4,
	0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07,
	0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
	0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856,
	0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,
	0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4,
	0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
	0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3,
	0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A,
	0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599,
	0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
	0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190,
	0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,
	0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E,
	0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
	0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED,
	0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950,
	0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3,
	0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
	0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A,
	0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5,
	0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010,
	0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
	0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17,
	0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6,
	0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615,
	0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
	0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344,
	0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
	0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A,
	0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
	0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1,
	0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C,
	0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF,
	0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
	0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE,
	0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31,
	0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C,
	0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
	0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B,
	0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
	0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1,
	0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
	0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278,
	0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7,
	0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66,
	0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
	0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605,
	0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8,
	0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B,
	0x2D02EF8D};
/********************************************************************************
 * GetCrc32
 *********************************************************************************/
uint32_t GetCrc32(uint8_t *InStr,uint32_t len,uint32_t value)
{
    uint32_t i;
    uint32_t Crc;

    Crc=value;

    for(i=0; i<len; i++)
    {
        Crc = (Crc >> 8) ^ CRC32_Table[(Crc&0xFF)^(InStr[i])];
    }

    return Crc;
}

/********************************************************************************
 * Function Name : LT_ReceiveCmd
 * Description   : Instruction processing.
 * Input         : - buf: Buffer address of instruction
 * Output        : None
 * Return        : None
 *********************************************************************************/
void LT_ReceiveCmd(uint8_t *buf)
{
	uint8_t cmd = 0, temp = 0, num = 0, cnt = 0;
	uint8_t rebuf[2100];
	uint16_t i = 0, j = 0;
	uint16_t rxCrc, mcuCrc;
	uint16_t addr = 0xFFFF;
	uint16_t count1 = 0, count2 = 0;
	uint32_t eflash_addr = 0, len = 0;
	uint32_t File_CRC = 0;
	

	gUsartRx.Flag = 0;
	
	if (CRC_Enable_Flag)
	{
		rxCrc = buf[gUsartRx.Count - 1];
		rxCrc = (rxCrc << 8) + buf[gUsartRx.Count - 2];
		//mcuCrc = CRC16(&buf[1], gUsartRx.Count - 3);
		if (buf[0] != 0)
		{
			mcuCrc = CRC16(&buf[1], gUsartRx.Count - 3);
		}
		else if (buf[0] == 0)
		{
			mcuCrc = CRC16(&buf[3], gUsartRx.Count - 5);
		}
	}
	else
		rxCrc = mcuCrc;

	if (buf[0] != 0)
	{
		cmd = buf[1];
		if (cmd == 0x03 || cmd == 0x10)
		{
			if (rxCrc == mcuCrc) // CRC OK
			{
				if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
				{
					rebuf[3] = cmd;
					rebuf[4] = 0xFF;
					LT_SendData_CRC_Frame(rebuf, 2);
				}

				/***************************Read instruction***************************/
				if (cmd == 0x03)
				{
					addr = (buf[2] << 8) | buf[3];
					len = (buf[4] << 8) | buf[5];
					
					Var_AddrRemapping(&addr);

					for (i = 0; i < 5; i++)
					{
						rebuf[3 + i] = buf[1 + i];
					}

					if (addr < VAR_ADDR_S) // Variable address
					{
						for (i = 0; i < len; i++)
						{
							rebuf[8 + 2 * i] = var[2 * (addr + i)];
							rebuf[9 + 2 * i] = var[2 * (addr + i) + 1];
						}
					}
					else if (addr >= VAR_ADDR_S && addr <= VAR_ADDR_E)
					{

						if (addr + len >= VAR_TIME || addr <= (VAR_TIME + 5))
						{
							var[VAR_TIME * 2 + 1] = calendar.w_year - 2000;
							var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
							var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
							var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
							var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
							var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
						}
						for (i = 0; i < len; i++)
						{
							rebuf[8 + 2 * i] = var[2 * (addr + i)];
							rebuf[9 + 2 * i] = var[2 * (addr + i) + 1];
						}
					}

					LT_SendData_CRC_Frame(rebuf, 5 + len * 2);
				}
				/***************************Write instructions***************************/
				else if (cmd == 0x10)
				{
					addr = (buf[2] << 8) | buf[3];
					if (CRC_Enable_Flag)
						len = (buf[0] - 2 - 3) / 2;
					else
						len = (buf[0] - 3) / 2;
					
					Var_AddrRemapping(&addr);

					if (addr < VAR_ADDR_S) // Variable address
					{
						// save data
						for (i = 0; i < len; i++)
						{
							var[2 * (addr + i)] = buf[4 + 2 * i];
							var[2 * (addr + i) + 1] = buf[5 + 2 * i];
						}

					}
					else if (addr >= VAR_ADDR_S && addr <= VAR_ADDR_E)
					{

						for (i = 0; i < len; i++)
						{
							var[2 * (addr + i)] = buf[4 + 2 * i];
							var[2 * (addr + i) + 1] = buf[5 + 2 * i];
						}

						for (i = 0; i < len;)
						{
							if ((addr + i) == VAR_PAGE) // page
							{
								if (pic_id != (var[VAR_PAGE * 2] << 8 | var[VAR_PAGE * 2 + 1]))
								{
									Display_page(var[VAR_PAGE * 2] << 8 | var[VAR_PAGE * 2 + 1]);
								}
								i++;
							}
							else if ((addr + i) == VAR_BL) // backlight
							{
								if (var[VAR_BL * 2 + 1] > 63)
									var[VAR_BL * 2 + 1] = 63;

								LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
								Backlight_flag = 1;
								
								i++;
							}
							else if ((addr + i) == VAR_TIME) // time
							{
								if (var[VAR_TIME * 2 + 1] > 99)
									var[VAR_TIME * 2 + 1] = 99;
								if (var[(VAR_TIME + 1) * 2 + 1] > 12)
									var[(VAR_TIME + 1) * 2 + 1] = 12;
								if (var[(VAR_TIME + 2) * 2 + 1] > 31)
									var[(VAR_TIME + 2) * 2 + 1] = 31;
								if (var[(VAR_TIME + 3) * 2 + 1] > 23)
									var[(VAR_TIME + 3) * 2 + 1] = 23;
								if (var[(VAR_TIME + 4) * 2 + 1] > 59)
									var[(VAR_TIME + 4) * 2 + 1] = 59;
								if (var[(VAR_TIME + 5) * 2 + 1] > 59)
									var[(VAR_TIME + 5) * 2 + 1] = 59;

								RTC_Set(2000 + var[VAR_TIME * 2 + 1], var[(VAR_TIME + 1) * 2 + 1], var[(VAR_TIME + 2) * 2 + 1], var[(VAR_TIME + 3) * 2 + 1], var[(VAR_TIME + 4) * 2 + 1], var[(VAR_TIME + 5) * 2 + 1]);
								i += 6;
							}
							else if ((addr + i) == VAR_TIMESET) // time setting
							{
								i++;
							}
							else if ((addr + i) == VAR_RSIZE_9) // NULL
							{
								i++;
							}
							else if ((addr + i) == VAR_WAV) // WAV
							{
								Wav_DAC_Init((var[VAR_WAV * 2] << 8) | var[VAR_WAV * 2 + 1]);
								i++;
							}
							else if ((addr + i) == VAR_VOLUME) // sound volume
							{
								if (var[2 * VAR_VOLUME + 1] > 16)
									wav_reduce_para = 16;
								else
									wav_reduce_para = var[2 * VAR_VOLUME + 1];
								i++;
							}
							else if ((addr + i) == VAR_RTP) // RTP calibration
							{
								if (var[VAR_RTP * 2 + 1] == 0x5A)
								{
	#if (LT_TOUCH_FLAG == 1)
									LT_TpAdjust();
	#endif
									var[VAR_RTP * 2 + 1] = 0x00;
									Display_page(((var[VAR_PAGE * 2] << 8) | var[VAR_PAGE * 2 + 1]));
								}
								i++;
							}
							else if ((addr + i) == VAR_KEY) // Key code trigger
							{
								Button_Key_Code = (var[VAR_KEY * 2] << 8) | var[VAR_KEY * 2 + 1];
								Button_Key_Code_Flag = 1;
								i++;
							}
							else if ((addr + i) == VAR_BLAUTO)
							{
								if(var[2 * VAR_BLAUTO + 1] == 1)
								{
									if (Backlight_flag == 0)
									{	
										Backlight_count = 0;								
										Backlight_flag = 1;
										LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
									}
								}
								else if (var[2 * VAR_BLAUTO + 1] == 0)
								{
									Backlight_count = 0;								
									Backlight_flag = 0;
									LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
								}
								i++;
							}
							else if ((addr + i) == VAR_BLSLEEP)
							{
								if (Backlight_flag == 0 && var[2 * VAR_BLAUTO + 1] == 1)
								{
									LT_BacklightSet(gDutyBuf[var[VAR_BLSLEEP * 2 + 1]]);
								}
								i++;
							}
							else if ((addr + i) == VAR_MCURESET)
							{
								if (var[2 * VAR_MCURESET] == 0xAA && var[2 * VAR_MCURESET + 1] == 0x55)
								{
									var[2 * VAR_MCURESET] = 0;
									var[2 * VAR_MCURESET + 1] = 0;
									SCI3->SCICR2 &=~(1<<2);
									SCI3->SCICR2 &=~(1<<3);
									SCI3->SCICR2 &=~(1<<5);
									
									PIT1->PCSR&=~PCSR_PIE;
									PIT1->PCSR&=~PCSR_EN;
									
									APP(0x8000000);
								}
								i++;
							}
							else if ((addr + i) == VAR_MTLANGUAGE)
							{
								if (var[2 * VAR_MTLANGUAGE + 1] < multi_language_count && var[2 * VAR_MTLANGUAGE + 1] != multi_language)
								{
									uint32_t language_sum = 0,language_count = 0,L_count = 0;
									uint32_t language_addr = 0,L_addr,L_len = 0;
									uint16_t L_num;
									
									multi_language = var[2 * VAR_MTLANGUAGE + 1];
									
									LT_ReadFlash_UI(rebuf,addr_index[18] + 8 * multi_language,8);
									language_addr = (rebuf[0]) + (rebuf[1] << 8) + (rebuf[2] << 16) + (rebuf[3] << 24);
									language_sum = (rebuf[4]) + (rebuf[5] << 8) + (rebuf[6] << 16) + (rebuf[7] << 24);

									if (language_sum - language_count >=2048)
											LT_ReadFlash_UI(rebuf,language_addr,2048);
									else 
										LT_ReadFlash_UI(rebuf,language_addr,language_sum);

									while(1)
									{
										if (L_count + 4 > 2048)
										{
											if (language_sum - language_count >= 2048)
												LT_ReadFlash_UI(rebuf,language_addr + language_count,2048);
											else 
												LT_ReadFlash_UI(rebuf,language_addr + language_count,language_sum - language_count);
											L_count = 0;
												
										}
										L_addr = rebuf[L_count] + (rebuf[L_count + 1] << 8);
										L_len = rebuf[L_count + 2] + (rebuf[L_count + 3] << 8);
										L_count = L_count + 4;
										
										if(L_count + L_len > 2048)
										{
											if (language_sum - (language_count + 4) >= 2048)
												LT_ReadFlash_UI(rebuf,language_addr + language_count + 4,2048);
											else 
												LT_ReadFlash_UI(rebuf,language_addr + language_count + 4 ,language_sum - (language_count + 4));
											L_count = 0;
										}

										for (uint16_t ll = 0; ll < L_len; ll++)
										{
											var[L_addr * 2 + ll] = rebuf[L_count + ll];
										}
										language_count += L_len + 4;
										L_count += L_len;
										
										if(language_count >= language_sum)
											break;
									}

									if(Pop_up_flag == 1)
									{
										Display_pop_up(Pop_up_id,Pop_up_x,Pop_up_y);
									}
									else Display_page(pic_id);
								}
								else
									var[2 * VAR_MTLANGUAGE + 1] = multi_language;

								i++;
							}
							else if ((addr + i) == VAR_UI_CHANGE)
							{
								if(lt_screen_dir != var[VAR_UI_CHANGE * 2 + 1])
									LT_LCD_screen_dir(var[VAR_UI_CHANGE * 2 + 1]);
								i++;
							}
							else if ((addr + i) == VAR_UI_UPDATE)
							{
								if (var[2 * VAR_UI_UPDATE + 1] == 0 && UI_update == 1)
								{
									UI_update = 0;
									Address_Index(); 		// Get address index
									LT_ReadParam();
									if (Start_page > addr_index[7])
										Display_page(0);
									else
										Display_page(Start_page);
								}
								else if (var[2 * VAR_UI_UPDATE + 1] == 1 && UI_update == 0)
								{
									LT268_TFT_FillColor(0,0,LCD_XSIZE_TFT-1,LCD_YSIZE_TFT-1,Blue2);
									LT268_TFT_ShowAscll(0, 10, 24, 0, Red, White, (uint8_t *)"Update Flash");
									UI_update = 1;
								}
								i++;
							}
							else
							{
								i++;
							}
						}
					}
					else if (addr >= VAR_CURVE_WS && addr <= VAR_CURVE_WE) // Curve channel address for write
					{
						temp = addr & 0xFFF;
						for (i = 0; i < CURVE_SIZE; i++)
						{
							if (temp & (1 << i))
								num++; // Record the number of channel groups
						}

						i = 0;
						j = 0;
						while (j < len) // Store data to corresponding channels respectively
						{
							if (temp & (1 << i))
							{
								Curve_buff[i][Curve_count[i]] = buf[4 + 2 * j] << 8 | buf[5 + 2 * j];
								Curve_count[i]++;
								if (Curve_count[i] >= 1024)
								{
									Curve_count[i] = 0;
								}
								curve_update_flag[i] = 1;
								j++;
							}
							i++;
							if (i >= CURVE_SIZE)
								i = 0;
						}

						if (len % num) // When multi-channel buffer data is triggered, if some channel data is missing, the missing part will be supplemented
						{
							for (i = 0; i < CURVE_SIZE; i++)
							{
								if (temp & (1 << i))
									cnt++;
								if (cnt > len % num && (temp & (1 << i)))
								{
									if (Curve_count[i] != 0)
										Curve_buff[i][Curve_count[i]] = Curve_buff[i][Curve_count[i] - 1];
									else
										Curve_buff[i][0] = Curve_buff[i][1023];

									Curve_count[i]++;
									if (Curve_count[i] >= 1024)
									{
										Curve_count[i] = 0;
									}
								}
							}
						}
					}
					else if (addr >= VAR_CURVE_CS && addr <= VAR_CURVE_CE) // Curve channel address for clear
					{
						temp = addr & 0xFFF;

						i = 0;
						j = 0;
						for (i = 0; i < CURVE_SIZE; i++) // clear data
						{
							if (temp & (1 << i))
							{
								for (j = 0; j < 1024; j++)
								{
									Curve_buff[i][j] = 0x00;
								}

								Curve_count[i] = 0;
								curve_update_flag[i] = 1;
							}
						}
					}
				}
			}
			else // CRC NG
			{
				if (CRC_Feedback_Flag) // CRC feedback is the default
				{
					rebuf[3] = cmd;
					rebuf[4] = 0x00;
					LT_SendData_CRC_Frame(rebuf, 2);
				}
			}
		}
		else if (cmd == 0x61 || cmd == 0x62 || cmd == 0x65 || cmd == 0x66)
		{
			U_UpdateCMDanalyse(cmd, buf);
		}
	}
	else if (buf[0] == 0)
	{
		cmd = buf[3];
		if (rxCrc == mcuCrc) // CRC OK
		{
			if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
			{
				rebuf[3] = cmd;
				rebuf[4] = 0xFF;
				LT_SendData_CRC_Frame(rebuf, 2);
			}
			
			if (cmd == 0x61)
			{
				len = (buf[1] << 8) | buf[2];
				eflash_addr = 0x804B000 + ((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]);
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();

				temp = EFLASH_Write(eflash_addr,&buf[8],len-7);

				EFLASH_ClrWritePermission();
				
				if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
				{
					rebuf[5] = cmd;
					rebuf[6] = buf[4];
					rebuf[7] = buf[5];
					rebuf[8] = buf[6];
					rebuf[9] = buf[7];
					rebuf[10] = 0x4F;
					rebuf[11] = 0x4B;
                    
					LT_SendFlashData_CRC_Frame(rebuf, 7);
				}
			}
			else if (cmd == 0x62)
			{
				len = (buf[8] << 8) | buf[9];
				if (len > 2048) len = 2048;
				eflash_addr = 0x804B000 + ((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]);
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				EFLASH_WordsRead_8(eflash_addr,&rebuf[10],len);
				EFLASH_ClrWritePermission();
				
				if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
				{
					rebuf[5] = cmd;
					rebuf[6] = buf[4];
					rebuf[7] = buf[5];
					rebuf[8] = buf[6];
					rebuf[9] = buf[7];
					LT_SendFlashData_CRC_Frame(rebuf, len + 5);
				}
			}
			else if (cmd == 0x63)
			{
				len = (buf[8] << 24) | (buf[9] << 16) | (buf[10] << 8) | buf[11];
				count1 = len / 2048;
				count2 = len % 2048;
				eflash_addr = 0x804B000 + ((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]);
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				for(i = 0; i < count1; i++)
				{
					EFLASH_WordsRead_8(eflash_addr + 2048 * i,rebuf,2048);
					File_CRC = GetCrc32(rebuf,2048,File_CRC);
				}
				if(count2 > 0)
				{
					EFLASH_WordsRead_8(eflash_addr + 2048 * i,rebuf,count2);
					File_CRC = GetCrc32(rebuf,count2,File_CRC);
				}
				EFLASH_ClrWritePermission();
				
				if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
				{
					rebuf[5] = cmd;
					rebuf[6] = buf[4];
					rebuf[7] = buf[5];
					rebuf[8] = buf[6];
					rebuf[9] = buf[7];
					rebuf[10] = (File_CRC >> 24) & 0xFF;
					rebuf[11] = (File_CRC >> 16) & 0xFF;
					rebuf[12] = (File_CRC >> 8) & 0xFF;
					rebuf[13] = File_CRC & 0xFF;
					LT_SendFlashData_CRC_Frame(rebuf, 9);
				}
			}
			else if (cmd == 0x64)
			{
				len = (buf[1] << 8) | buf[2];
				eflash_addr = ((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]);

//				Flash_Write_NoCheck(&buf[8],eflash_addr,len-7);
			    LT_WinbondFlash_write_2K(&buf[8],eflash_addr,len-7);
				
				if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
				{
					rebuf[5] = cmd;
					rebuf[6] = buf[4];
					rebuf[7] = buf[5];
					rebuf[8] = buf[6];
					rebuf[9] = buf[7];
					rebuf[10] = 0x4F;
					rebuf[11] = 0x4B;
			
					LT_SendFlashData_CRC_Frame(rebuf, 7);
				}
			}
			else if (cmd == 0x65)
			{
				len = (buf[8] << 8) | buf[9];
				if (len > 2048) len = 2048;
				eflash_addr = ((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]);

				LT_ReadFlash_DMA(&rebuf[10],eflash_addr,len);
		
				if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
				{
					rebuf[5] = cmd;
					rebuf[6] = buf[4];
					rebuf[7] = buf[5];
					rebuf[8] = buf[6];
					rebuf[9] = buf[7];
					LT_SendFlashData_CRC_Frame(rebuf, len + 5);
				}
			}
			else if (cmd == 0x66)
			{
				len = (buf[8] << 24) | (buf[9] << 16) | (buf[10] << 8) | buf[11];
				count1 = len / 2048;
				count2 = len % 2048;
				eflash_addr = ((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]);
				
				for(i = 0; i < count1; i++)
				{
					LT_ReadFlash_DMA(rebuf,eflash_addr + 2048 * i,2048);
					File_CRC = GetCrc32(rebuf,2048,File_CRC);
				}
				
				if(count2 > 0)
				{
					LT_ReadFlash_DMA(rebuf,eflash_addr + 2048 * i,count2);
					File_CRC = GetCrc32(rebuf,count2,File_CRC);
				}

				if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
				{
					rebuf[5] = cmd;
					rebuf[6] = buf[4];
					rebuf[7] = buf[5];
					rebuf[8] = buf[6];
					rebuf[9] = buf[7];
					rebuf[10] = (File_CRC >> 24) & 0xFF;
					rebuf[11] = (File_CRC >> 16) & 0xFF;
					rebuf[12] = (File_CRC >> 8) & 0xFF;
					rebuf[13] = File_CRC & 0xFF;
					LT_SendFlashData_CRC_Frame(rebuf, 9);
				}
			}
		}
		else // CRC NG
		{
			if (CRC_Feedback_Flag) // CRC feedback is the default
			{
				rebuf[3] = cmd;
				rebuf[4] = 0x00;
				LT_SendData_CRC_Frame(rebuf, 2);
			}
		}
	}
	
	
	gUsartRx.Flag = 0;
	gUsartRx.Count = 0; // Clear to receive the next data
	LT_ClearRxBuf();	// Clear receive buffer
}

#if (UARTBUS_OPTION == 1) || (UARTBUS_OPTION == 2)
void LT_ModBus_REG_Cmd(void)
{

	uint16_t i = 0;
	for (i = 0; i < sizeof(flag_MB_REG);)
	{
		if (i == 0 && flag_MB_REG[i])
		{
			if (pic_id != (var[2 * VAR_PAGE] << 8 | var[2 * VAR_PAGE + 1]))
			{
				Display_page(var[2 * VAR_PAGE] << 8 | var[2 * VAR_PAGE + 1]);
			}
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 1 && flag_MB_REG[i])
		{
			if (var[VAR_BL * 2 + 1] > 63)
				var[VAR_BL * 2 + 1] = 63;

			LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
			Backlight_flag = 1;

			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 2 && flag_MB_REG[i]) // time
		{
			if (var[VAR_TIME * 2 + 1] > 99)
				var[VAR_TIME * 2 + 1] = 99;
			if (var[(VAR_TIME + 1) * 2 + 1] > 12)
				var[(VAR_TIME + 1) * 2 + 1] = 12;
			if (var[(VAR_TIME + 2) * 2 + 1] > 31)
				var[(VAR_TIME + 2) * 2 + 1] = 31;
			if (var[(VAR_TIME + 3) * 2 + 1] > 23)
				var[(VAR_TIME + 3) * 2 + 1] = 23;
			if (var[(VAR_TIME + 4) * 2 + 1] > 59)
				var[(VAR_TIME + 4) * 2 + 1] = 59;
			if (var[(VAR_TIME + 5) * 2 + 1] > 59)
				var[(VAR_TIME + 5) * 2 + 1] = 59;

			RTC_Set(2000 + var[(VAR_TIME + 0) * 2 + 1], var[(VAR_TIME + 1) * 2 + 1], var[(VAR_TIME + 2) * 2 + 1], var[(VAR_TIME + 3) * 2 + 1], var[(VAR_TIME + 4) * 2 + 1], var[(VAR_TIME + 5) * 2 + 1]);
			flag_MB_REG[i] = 0;
			i += 6;
		}
		else if (i == 8 && flag_MB_REG[i] == 1) // time setting
		{
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 9 && flag_MB_REG[i] == 1) // NULL
		{
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 10 && flag_MB_REG[i] == 1) // WAV
		{
			Wav_DAC_Init((var[VAR_WAV * 2] << 8) | var[VAR_WAV * 2 + 1]);
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 11 && flag_MB_REG[i] == 1) // sound volume
		{
			if (var[2 * VAR_VOLUME + 1] > 16)
				wav_reduce_para = 16;
			else
				wav_reduce_para = var[2 * VAR_VOLUME + 1];
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 12 && flag_MB_REG[i] == 1) // RTP calibration
		{
			if (var[VAR_RTP * 2 + 1] == 0x5A)
			{
#if (LT_TOUCH_FLAG == 1)
				LT_TpAdjust();
#endif
				var[VAR_RTP * 2 + 1] = 0x00;
				Display_page(((var[VAR_PAGE * 2] << 8) | var[VAR_PAGE * 2 + 1]));
			}
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 13 && flag_MB_REG[i] == 1) // Key code trigger
		{
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 14 && flag_MB_REG[i] == 1)
		{
			if(var[2 * VAR_BLAUTO + 1] == 1)
			{
				if (Backlight_flag == 0)
				{	
					Backlight_count = 0;								
					Backlight_flag = 1;
					LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
				}
			}
			else if (var[2 * VAR_BLAUTO + 1] == 0)
			{
				Backlight_count = 0;								
				Backlight_flag = 0;
				LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
			}
			flag_MB_REG[i] = 0;
			i++;	
		}
		else if (i == 15 && flag_MB_REG[i] == 1)
		{
			if (Backlight_flag == 0 && var[2 * VAR_BLAUTO + 1] == 1)
			{
				LT_BacklightSet(gDutyBuf[var[VAR_BLSLEEP * 2 + 1]]);
			}
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 17 && flag_MB_REG[i] == 1)
		{
			if (var[2 * VAR_MCURESET] == 0xAA && var[2 * VAR_MCURESET + 1] == 0x55)
			{
				var[2 * VAR_MCURESET] = 0;
				var[2 * VAR_MCURESET + 1] = 0;
				SCI3->SCICR2 &=~(1<<2);
				SCI3->SCICR2 &=~(1<<3);
				SCI3->SCICR2 &=~(1<<5);
				
				PIT1->PCSR&=~PCSR_PIE;
				PIT1->PCSR&=~PCSR_EN;	
				APP(0x8000000);
			}
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 0x3F && flag_MB_REG[i] == 1)
		{
			if (var[2 * VAR_MTLANGUAGE + 1] < multi_language_count && var[2 * VAR_MTLANGUAGE + 1] != multi_language)
			{
				uint32_t language_sum = 0,language_count = 0,L_count = 0;
				uint32_t language_addr = 0,L_addr,L_len = 0;
				uint16_t L_num;
				uint8_t rebuf[2100];

				multi_language = var[2 * VAR_MTLANGUAGE + 1];
				
				LT_ReadFlash_UI(rebuf,addr_index[18] + 8 * multi_language,8);
				language_addr = (rebuf[0]) + (rebuf[1] << 8) + (rebuf[2] << 16) + (rebuf[3] << 24);
				language_sum = (rebuf[4]) + (rebuf[5] << 8) + (rebuf[6] << 16) + (rebuf[7] << 24);

				if (language_sum - language_count >=2048)
						LT_ReadFlash_UI(rebuf,language_addr,2048);
				else 
					LT_ReadFlash_UI(rebuf,language_addr,language_sum);

				while(1)
				{
					if (L_count + 4 > 2048)
					{
						if (language_sum - language_count >= 2048)
							LT_ReadFlash_UI(rebuf,language_addr + language_count,2048);
						else 
							LT_ReadFlash_UI(rebuf,language_addr + language_count,language_sum - language_count);
						L_count = 0;
							
					}
					L_addr = rebuf[L_count] + (rebuf[L_count + 1] << 8);
					L_len = rebuf[L_count + 2] + (rebuf[L_count + 3] << 8);
					L_count = L_count + 4;
					
					if(L_count + L_len > 2048)
					{
						if (language_sum - (language_count + 4) >= 2048)
							LT_ReadFlash_UI(rebuf,language_addr + language_count + 4,2048);
						else 
							LT_ReadFlash_UI(rebuf,language_addr + language_count + 4 ,language_sum - (language_count + 4));
						L_count = 0;
					}

					for (uint16_t ll = 0; ll < L_len; ll++)
					{
						var[L_addr * 2 + ll] = rebuf[L_count + ll];
					}
					language_count += L_len + 4;
					L_count += L_len;
					
					if(language_count >= language_sum)
						break;
				}

				if(Pop_up_flag == 1)
				{
					Display_pop_up(Pop_up_id,Pop_up_x,Pop_up_y);
				}
				else Display_page(pic_id);
			}
			else
				var[2 * VAR_MTLANGUAGE + 1] = multi_language;
			
			flag_MB_REG[i] = 0;
			i++;
		}
		else if (i == 0x40 && flag_MB_REG[i] == 1)
		{
			if(lt_screen_dir != var[VAR_UI_CHANGE * 2 + 1])
				LT_LCD_screen_dir(var[VAR_UI_CHANGE * 2 + 1]);
				
			flag_MB_REG[i] = 0;
			i++;
		}
		else
		{
			i++;
		}
	}
}

#endif

#if (UARTBUS_OPTION == 3)
void LT_IIC_REG_Cmd(void)
{
	uint16_t i = 0;
	for (i = 0; i < sizeof(flag_MB_REG);)
	{
		if (i == 0 && flag_IIC_REG[i] == 1)
		{
			Display_page(var[VAR_PAGE * 2] << 8 | var[VAR_PAGE * 2 + 1]);
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 1 && flag_IIC_REG[i] == 1)
		{
			if (var[VAR_BL * 2 + 1] > 63)
				var[VAR_BL * 2 + 1] = 63;

			LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
			Backlight_flag = 1;


			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 2 && flag_IIC_REG[i] == 1)
		{
			if (var[(VAR_TIME + 0) * 2 + 1] > 99)
				var[(VAR_TIME + 0) * 2 + 1] = 99;
			if (var[(VAR_TIME + 1) * 2 + 1] > 12)
				var[(VAR_TIME + 1) * 2 + 1] = 12;
			if (var[(VAR_TIME + 2) * 2 + 1] > 31)
				var[(VAR_TIME + 2) * 2 + 1] = 31;
			if (var[(VAR_TIME + 3) * 2 + 1] > 23)
				var[(VAR_TIME + 3) * 2 + 1] = 23;
			if (var[(VAR_TIME + 4) * 2 + 1] > 59)
				var[(VAR_TIME + 4) * 2 + 1] = 59;
			if (var[(VAR_TIME + 5) * 2 + 1] > 59)
				var[(VAR_TIME + 5) * 2 + 1] = 59;

			RTC_Set(2000 + var[(VAR_TIME + 0) * 2 + 1], var[(VAR_TIME + 1) * 2 + 1], var[(VAR_TIME + 2) * 2 + 1], var[(VAR_TIME + 3) * 2 + 1], var[(VAR_TIME + 4) * 2 + 1], var[(VAR_TIME + 5) * 2 + 1]);
			flag_IIC_REG[i] = 0;
			i += 6;
		}
		else if (i == 8 && flag_IIC_REG[i] == 1)
		{
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 9 && flag_IIC_REG[i] == 1)
		{
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 10 && flag_IIC_REG[i] == 1)
		{
			var[VAR_WAV * 2] = ID_IIC_WAV >> 8;
			var[VAR_WAV * 2 + 1] = ID_IIC_WAV & 0xFF;

			Wav_DAC_Init((var[VAR_WAV * 2] << 8) | var[VAR_WAV * 2 + 1]);
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 11 && flag_IIC_REG[i] == 1)
		{
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 12 && flag_IIC_REG[i] == 1)
		{
			if (var[VAR_RTP * 2 + 1] == 0x5A)
			{
#if (LT_TOUCH_FLAG == 1)
				LT_TpAdjust();
#endif
				var[VAR_RTP * 2 + 1] = 0x00;
				Display_page(((var[VAR_PAGE * 2] << 8) | var[VAR_PAGE * 2 + 1]));
			}
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 13 && flag_IIC_REG[i] == 1)
		{
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 14 && flag_IIC_REG[i] == 1)
		{
			if(var[2 * VAR_BLAUTO + 1] == 1)
			{
				if (Backlight_flag == 0)
				{	
					Backlight_count = 0;								
					Backlight_flag = 1;
					LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
				}
			}
			else if (var[2 * VAR_BLAUTO + 1] == 0)
			{
				Backlight_count = 0;								
				Backlight_flag = 0;
				LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
			}
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 15 && flag_IIC_REG[i] == 1)
		{
			if (Backlight_flag == 0 && var[2 * VAR_BLAUTO + 1] == 1)
			{
				LT_BacklightSet(gDutyBuf[var[VAR_BLSLEEP * 2 + 1]]);
			}
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 17 && flag_IIC_REG[i] == 1)
		{
			if (var[2 * VAR_MCURESET] == 0xAA && var[2 * VAR_MCURESET + 1] == 0x55)
			{
				var[2 * VAR_MCURESET] = 0;
				var[2 * VAR_MCURESET + 1] = 0;
				SCI3->SCICR2 &=~(1<<2);
				SCI3->SCICR2 &=~(1<<3);
				SCI3->SCICR2 &=~(1<<5);
				
				PIT1->PCSR&=~PCSR_PIE;
				PIT1->PCSR&=~PCSR_EN;	
				APP(0x8000000);
			}
			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 0x3F && flag_IIC_REG[i] == 1)
		{
			if (var[2 * VAR_MTLANGUAGE + 1] < multi_language_count && var[2 * VAR_MTLANGUAGE + 1] != multi_language)
			{
				uint32_t language_sum = 0,language_count = 0,L_count = 0;
				uint32_t language_addr = 0,L_addr,L_len = 0;
				uint16_t L_num;
				uint8_t rebuf[2100];
				
				multi_language = var[2 * VAR_MTLANGUAGE + 1];
				
				LT_ReadFlash_UI(rebuf,addr_index[18] + 8 * multi_language,8);
				language_addr = (rebuf[0]) + (rebuf[1] << 8) + (rebuf[2] << 16) + (rebuf[3] << 24);
				language_sum = (rebuf[4]) + (rebuf[5] << 8) + (rebuf[6] << 16) + (rebuf[7] << 24);

				if (language_sum - language_count >=2048)
						LT_ReadFlash_UI(rebuf,language_addr,2048);
				else 
					LT_ReadFlash_UI(rebuf,language_addr,language_sum);

				while(1)
				{
					if (L_count + 4 > 2048)
					{
						if (language_sum - language_count >= 2048)
							LT_ReadFlash_UI(rebuf,language_addr + language_count,2048);
						else 
							LT_ReadFlash_UI(rebuf,language_addr + language_count,language_sum - language_count);
						L_count = 0;
							
					}
					L_addr = rebuf[L_count] + (rebuf[L_count + 1] << 8);
					L_len = rebuf[L_count + 2] + (rebuf[L_count + 3] << 8);
					L_count = L_count + 4;
					
					if(L_count + L_len > 2048)
					{
						if (language_sum - (language_count + 4) >= 2048)
							LT_ReadFlash_UI(rebuf,language_addr + language_count + 4,2048);
						else 
							LT_ReadFlash_UI(rebuf,language_addr + language_count + 4 ,language_sum - (language_count + 4));
						L_count = 0;
					}

					for (uint16_t ll = 0; ll < L_len; ll++)
					{
						var[L_addr * 2 + ll] = rebuf[L_count + ll];
					}
					language_count += L_len + 4;
					L_count += L_len;
					
					if(language_count >= language_sum)
						break;
				}

				if(Pop_up_flag == 1)
				{
					Display_pop_up(Pop_up_id,Pop_up_x,Pop_up_y);
				}
				else Display_page(pic_id);
			}
			else
				var[2 * VAR_MTLANGUAGE + 1] = multi_language;

			flag_IIC_REG[i] = 0;
			i++;
		}
		else if (i == 0x40 && flag_IIC_REG[i] == 1)
		{
			if(lt_screen_dir != var[VAR_UI_CHANGE * 2 + 1])
				LT_LCD_screen_dir(var[VAR_UI_CHANGE * 2 + 1]);
				
			flag_IIC_REG[i] = 0;
			i++;
		}
		else
		{
			i++;
		}
	}
}
#endif

#if (UARTBUS_OPTION == 5 || UARTBUS_OPTION == 6)
void LT_Hid_ReceiveCmd(uint8_t *buf)
{
	uint16_t i = 0;
	uint16_t j = 0;
	uint8_t cmd = 0;
	uint8_t rebuf[2100];
	uint16_t rxCrc, mcuCrc;
	uint16_t addr = 0xFFFF;
	uint8_t num = 0, cnt = 0;
	uint16_t temp = 0,count1 = 0, count2 = 0;
	uint32_t eflash_addr = 0, len = 0;
	uint32_t File_CRC = 0;
	
	uint32_t language_sum = 0,language_count = 0,L_count = 0;
	uint32_t language_addr = 0,L_addr,L_len = 0;
	uint16_t L_num;
	
	gHidRx.Flag = 0;
	
	if (CRC_Enable_Flag)
	{
		rxCrc = buf[gHidRx.Count - 1];
		rxCrc = (rxCrc << 8) + buf[gHidRx.Count - 2];
		if (buf[0] != 0)
		{
			mcuCrc = CRC16(&buf[1], gHidRx.Count - 3);
		}
		else if (buf[0] == 0)
		{
			mcuCrc = CRC16(&buf[3], gHidRx.Count - 5);
		}
	}
	else
		rxCrc = mcuCrc;

	if (buf[0] != 0)
	{
		cmd = buf[1];

		if (rxCrc == mcuCrc) // CRC OK
		{
			if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
			{
				rebuf[3] = cmd;
				rebuf[4] = 0xFF;
				LT_SendData_CRC_Frame(rebuf, 2);
				DelayUS(1200);
			}

			/***************************Read instruction***************************/
			if (cmd == 0x03)
			{
				addr = (buf[2] << 8) | buf[3];
				len = (buf[4] << 8) | buf[5];
				
				Var_AddrRemapping(&addr);

				for (i = 0; i < 5; i++)
				{
					rebuf[3 + i] = buf[1 + i];
				}
				if (addr < VAR_ADDR_S) // Variable area
				{
					for (i = 0; i < len; i++)
					{
						rebuf[8 + 2 * i] = var[2 * (addr + i)];
						rebuf[9 + 2 * i] = var[2 * (addr + i) + 1];
					}
				}
				else if (addr >= VAR_ADDR_S && addr <= VAR_ADDR_E)
				{
					if (addr + len >= VAR_TIME || addr <= (VAR_TIME + 5))
					{
						var[VAR_TIME * 2 + 1] = calendar.w_year - 2000;
						var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
						var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
						var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
						var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
						var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
					}
					for (i = 0; i < len; i++)
					{
						rebuf[8 + 2 * i] = var[2 * (addr + i)];
						rebuf[9 + 2 * i] = var[2 * (addr + i) + 1];
					}
				}

				LT_SendData_CRC_Frame(rebuf, 5 + len * 2);
			}
			/***************************Write instructions***************************/
			else if (cmd == 0x10)
			{
				addr = (buf[2] << 8) | buf[3];
				if (CRC_Enable_Flag)
					len = (buf[0] - 2 - 3) / 2;
				else
					len = (buf[0] - 3) / 2;
				
				Var_AddrRemapping(&addr);

				if (addr < VAR_ADDR_S) // Variable area
				{
					// Save data
					for (i = 0; i < len; i++)
					{
						var[2 * (addr + i)] = buf[4 + 2 * i];
						var[2 * (addr + i) + 1] = buf[5 + 2 * i];
					}
				}
				else if (addr >= VAR_ADDR_S && addr <= VAR_ADDR_E)
				{
					for (i = 0; i < len; i++)
					{
						var[2 * (addr + i)] = buf[4 + 2 * i];
						var[2 * (addr + i) + 1] = buf[5 + 2 * i];
					}

					for (i = 0; i < len;)
					{
						if ((addr + i) == VAR_PAGE) // Page
						{
							if (pic_id != (var[VAR_PAGE * 2] << 8 | var[VAR_PAGE * 2 + 1]))
							{
								Display_page(var[VAR_PAGE * 2] << 8 | var[VAR_PAGE * 2 + 1]);
							}
							i++;
						}
						else if ((addr + i) == VAR_BL) // Backlight
						{
							if (var[VAR_BL * 2 + 1] > 63)
								var[VAR_BL * 2 + 1] = 63;

							LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
							Backlight_flag = 1;
							
							i++;
						}
						else if ((addr + i) == VAR_TIME) // Time
						{
							if (var[VAR_TIME * 2 + 1] > 99)
								var[VAR_TIME * 2 + 1] = 99;
							if (var[(VAR_TIME + 1) * 2 + 1] > 12)
								var[(VAR_TIME + 1) * 2 + 1] = 12;
							if (var[(VAR_TIME + 2) * 2 + 1] > 31)
								var[(VAR_TIME + 2) * 2 + 1] = 31;
							if (var[(VAR_TIME + 3) * 2 + 1] > 23)
								var[(VAR_TIME + 3) * 2 + 1] = 23;
							if (var[(VAR_TIME + 4) * 2 + 1] > 59)
								var[(VAR_TIME + 4) * 2 + 1] = 59;
							if (var[(VAR_TIME + 5) * 2 + 1] > 59)
								var[(VAR_TIME + 5) * 2 + 1] = 59;

							RTC_Set(2000 + var[VAR_TIME * 2 + 1], var[(VAR_TIME + 1) * 2 + 1], var[(VAR_TIME + 2) * 2 + 1], var[(VAR_TIME + 3) * 2 + 1], var[(VAR_TIME + 4) * 2 + 1], var[(VAR_TIME + 5) * 2 + 1]);
							i += 6;
						}
						else if ((addr + i) == VAR_TIMESET) // Time setting
						{
							i++;
						}
						else if ((addr + i) == VAR_RSIZE_9) // NULL
						{
							i++;
						}
						else if ((addr + i) == VAR_WAV) // WAV
						{
							Wav_DAC_Init((var[VAR_WAV * 2] << 8) | var[VAR_WAV * 2 + 1]);
							i++;
						}
						else if ((addr + i) == VAR_VOLUME) // Sound volume
						{
							if (var[2 * VAR_VOLUME + 1] > 16)
								wav_reduce_para = 16;
							else
								wav_reduce_para = var[2 * VAR_VOLUME + 1];
							i++;
						}
						else if ((addr + i) == VAR_RTP) // RTP calibration
						{
							if (var[VAR_RTP * 2 + 1] == 0x5A)
							{
#if (LT_TOUCH_FLAG == 1)
								LT_TpAdjust();
#endif
								var[VAR_RTP * 2 + 1] = 0x00;
								Display_page(((var[VAR_PAGE * 2] << 8) | var[VAR_PAGE * 2 + 1]));
							}
							i++;
						}
						else if ((addr + i) == VAR_KEY) // Key code trigger
						{
							Button_Key_Code = (var[VAR_KEY * 2] << 8) | var[VAR_KEY * 2 + 1];
							Button_Key_Code_Flag = 1;
							i++;
						}
						else if ((addr + i) == VAR_BLAUTO)
						{
							if(var[2 * VAR_BLAUTO + 1] == 1)
							{
								if (Backlight_flag == 0)
								{	
									Backlight_count = 0;								
									Backlight_flag = 1;
									LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
								}
							}
							else if (var[2 * VAR_BLAUTO + 1] == 0)
							{
								Backlight_count = 0;								
								Backlight_flag = 0;
								LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
							}
							i++;
						}
						else if ((addr + i) == VAR_BLSLEEP)
						{
							if (Backlight_flag == 0 && var[2 * VAR_BLAUTO + 1] == 1)
							{
								LT_BacklightSet(gDutyBuf[var[VAR_BLSLEEP * 2 + 1]]);
							}
							i++;
						}
						else if ((addr + i) == VAR_MCURESET)
						{
							if (var[2 * VAR_MCURESET] == 0xAA && var[2 * VAR_MCURESET + 1] == 0x55)
							{
								var[2 * VAR_MCURESET] = 0;
								var[2 * VAR_MCURESET + 1] = 0;
								SCI3->SCICR2 &=~(1<<2);
								SCI3->SCICR2 &=~(1<<3);
								SCI3->SCICR2 &=~(1<<5);
								
								PIT1->PCSR&=~PCSR_PIE;
								PIT1->PCSR&=~PCSR_EN;
								
								APP(0x8000000);
							}
							i++;
						}
						else if ((addr + i) == VAR_MTLANGUAGE)
						{
							if (var[2 * VAR_MTLANGUAGE + 1] < multi_language_count && var[2 * VAR_MTLANGUAGE + 1] != multi_language)
							{
								multi_language = var[2 * VAR_MTLANGUAGE + 1];
								
								LT_ReadFlash_UI(rebuf,addr_index[18] + 8 * multi_language,8);
								language_addr = (rebuf[0]) + (rebuf[1] << 8) + (rebuf[2] << 16) + (rebuf[3] << 24);
								language_sum = (rebuf[4]) + (rebuf[5] << 8) + (rebuf[6] << 16) + (rebuf[7] << 24);

								if (language_sum - language_count >=2048)
										LT_ReadFlash_UI(rebuf,language_addr,2048);
								else 
									LT_ReadFlash_UI(rebuf,language_addr,language_sum);

								while(1)
								{
									if (L_count + 4 > 2048)
									{
										if (language_sum - language_count >= 2048)
											LT_ReadFlash_UI(rebuf,language_addr + language_count,2048);
										else 
											LT_ReadFlash_UI(rebuf,language_addr + language_count,language_sum - language_count);
										L_count = 0;
											
									}
									L_addr = rebuf[L_count] + (rebuf[L_count + 1] << 8);
									L_len = rebuf[L_count + 2] + (rebuf[L_count + 3] << 8);
									L_count = L_count + 4;
									
									if(L_count + L_len > 2048)
									{
										if (language_sum - (language_count + 4) >= 2048)
											LT_ReadFlash_UI(rebuf,language_addr + language_count + 4,2048);
										else 
											LT_ReadFlash_UI(rebuf,language_addr + language_count + 4 ,language_sum - (language_count + 4));
										L_count = 0;
									}

									for (uint16_t ll = 0; ll < L_len; ll++)
									{
										var[L_addr * 2 + ll] = rebuf[L_count + ll];
									}
									language_count += L_len + 4;
									L_count += L_len;
									
									if(language_count >= language_sum)
										break;
								}

								if(Pop_up_flag == 1)
								{
									Display_pop_up(Pop_up_id,Pop_up_x,Pop_up_y);
								}
								else Display_page(pic_id);
							}
							else
								var[2 * VAR_MTLANGUAGE + 1] = multi_language;

							i++;
						}
						else if ((addr + i) == VAR_UI_CHANGE)
						{
							if(lt_screen_dir != var[VAR_UI_CHANGE * 2 + 1])
								LT_LCD_screen_dir(var[VAR_UI_CHANGE * 2 + 1]);
							
							i++;
						}
						else if ((addr + i) == VAR_UI_UPDATE)
						{
							if (var[2 * VAR_UI_UPDATE + 1] == 0 && UI_update == 1)
							{
								UI_update = 0;
								Address_Index(); 		// Get address index
								LT_ReadParam();
								if (Start_page > addr_index[7])
									Display_page(0);
								else
									Display_page(Start_page);
							}
							else if (var[2 * VAR_UI_UPDATE + 1] == 1 && UI_update == 0)
							{
								LT268_TFT_FillColor(0,0,LCD_XSIZE_TFT-1,LCD_YSIZE_TFT-1,Blue2);
								LT268_TFT_ShowAscll(0, 10, 24, 0, Red, White, (uint8_t *)"Update Flash");
								UI_update = 1;
							}
							i++;
						}
						else
						{
							i++;
						}
					}
				}
				else if (addr >= VAR_CURVE_WS && addr <= VAR_CURVE_WE) // Curve channel address for write
				{
					temp = addr & 0xFFF;
					for (i = 0; i < CURVE_SIZE; i++)
					{
						if (temp & (1 << i))
							num++; // Record the number of channel groups
					}

					i = 0;
					j = 0;
					while (j < len) // Store data to corresponding channels respectively
					{
						if (temp & (1 << i))
						{
							Curve_buff[i][Curve_count[i]] = buf[4 + 2 * j] << 8 | buf[5 + 2 * j];
							Curve_count[i]++;
							if (Curve_count[i] >= 1024)
							{
								Curve_count[i] = 0;
							}
							curve_update_flag[i] = 1;
							j++;
						}
						i++;
						if (i >= CURVE_SIZE)
							i = 0;
					}

					if (len % num) // When multi-channel buffer data is triggered, if some channel data is missing, the missing part will be supplemented
					{
						for (i = 0; i < CURVE_SIZE; i++)
						{
							if (temp & (1 << i))
								cnt++;
							if (cnt > len % num && (temp & (1 << i)))
							{
								if (Curve_count[i] != 0)
									Curve_buff[i][Curve_count[i]] = Curve_buff[i][Curve_count[i] - 1];
								else
									Curve_buff[i][0] = Curve_buff[i][1023];

								Curve_count[i]++;
								if (Curve_count[i] >= 1024)
								{
									Curve_count[i] = 0;
								}
							}
						}
					}
				}
				else if (addr >= VAR_CURVE_CS && addr <= VAR_CURVE_CE) // Curve channel address for clear
				{
					temp = addr & 0xFFF;

					i = 0;
					j = 0;
					for (i = 0; i < CURVE_SIZE; i++) // clear data
					{
						if (temp & (1 << i))
						{
							for (j = 0; j < 1024; j++)
							{
								Curve_buff[i][j] = 0x00;
							}

							Curve_count[i] = 0;
							curve_update_flag[i] = 1;
						}
					}
				}
			}
		}
		else // CRC NG
		{
			if (CRC_Feedback_Flag) // CRC feedback is the default
			{
				rebuf[3] = cmd;
				rebuf[4] = 0x00;
				LT_SendData_CRC_Frame(rebuf, 2);
			}
		}
	}
	else if (buf[0] == 0)
	{
		cmd = buf[3];
		if (rxCrc == mcuCrc) // CRC OK
		{
			if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
			{
				rebuf[3] = cmd;
				rebuf[4] = 0xFF;
				LT_SendData_CRC_Frame(rebuf, 2);
				DelayUS(1200);
			}
			
			if (cmd == 0x61)
			{
				len = (buf[1] << 8) | buf[2];
				eflash_addr = 0x804B000 + ((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]);
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();

				temp = EFLASH_Write(eflash_addr,&buf[8],len-7);

				EFLASH_ClrWritePermission();
				
				if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
				{
					rebuf[5] = cmd;
					rebuf[6] = buf[4];
					rebuf[7] = buf[5];
					rebuf[8] = buf[6];
					rebuf[9] = buf[7];
					rebuf[10] = 0x4F;
					rebuf[11] = 0x4B;
			
					LT_SendFlashData_CRC_Frame(rebuf, 7);
				}
			}
			else if (cmd == 0x62)
			{
				
				len = (buf[8] << 8) | buf[9];
				if (len > 2048) len = 2048;
				eflash_addr = 0x804B000 + ((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]);
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				EFLASH_WordsRead_8(eflash_addr,&rebuf[10],len);
				EFLASH_ClrWritePermission();
				
				if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
				{
					rebuf[5] = cmd;
					rebuf[6] = buf[4];
					rebuf[7] = buf[5];
					rebuf[8] = buf[6];
					rebuf[9] = buf[7];
					LT_SendFlashData_CRC_Frame(rebuf, len + 5);
				}
			}
			else if (cmd == 0x63)
			{
				len = (buf[8] << 24) | (buf[9] << 16) | (buf[10] << 8) | buf[11];
				count1 = len / 2048;
				count2 = len % 2048;
				eflash_addr = 0x804B000 + ((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]);
				EFLASH_Init(g_sys_clk / 1000);
				EFLASH_SetWritePermission();
				for(i = 0; i < count1; i++)
				{
					EFLASH_WordsRead_8(eflash_addr + 2048 * i,rebuf,2048);
					File_CRC = GetCrc32(rebuf,2048,File_CRC);
				}
				if(count2 > 0)
				{
					EFLASH_WordsRead_8(eflash_addr + 2048 * i,rebuf,count2);
					File_CRC = GetCrc32(rebuf,count2,File_CRC);
				}
				EFLASH_ClrWritePermission();
				
				if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
				{
					rebuf[5] = cmd;
					rebuf[6] = buf[4];
					rebuf[7] = buf[5];
					rebuf[8] = buf[6];
					rebuf[9] = buf[7];
					rebuf[10] = (File_CRC >> 24) & 0xFF;
					rebuf[11] = (File_CRC >> 16) & 0xFF;
					rebuf[12] = (File_CRC >> 8) & 0xFF;
					rebuf[13] = File_CRC & 0xFF;
					LT_SendFlashData_CRC_Frame(rebuf, 9);
				}
			}
			else if (cmd == 0x64)
			{
				len = (buf[1] << 8) | buf[2];
				eflash_addr = ((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]);

//				Flash_Write_NoCheck(&buf[8],eflash_addr,len-7);
				LT_WinbondFlash_write_2K(&buf[8],eflash_addr,len-7);

				if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
				{
					rebuf[5] = cmd;
					rebuf[6] = buf[4];
					rebuf[7] = buf[5];
					rebuf[8] = buf[6];
					rebuf[9] = buf[7];
					rebuf[10] = 0x4F;
					rebuf[11] = 0x4B;
					LT_SendFlashData_CRC_Frame(rebuf, 7);
				}
			}
			else if (cmd == 0x65)
			{
				len = (buf[8] << 8) | buf[9];
				if (len > 2048) len = 2048;
				eflash_addr = ((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]);

				LT_ReadFlash_DMA(&rebuf[10],eflash_addr,len);
		
				if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
				{
					rebuf[5] = cmd;
					rebuf[6] = buf[4];
					rebuf[7] = buf[5];
					rebuf[8] = buf[6];
					rebuf[9] = buf[7];
					LT_SendFlashData_CRC_Frame(rebuf, len + 5);
				}
			}
			else if (cmd == 0x66)
			{
				len = (buf[8] << 24) | (buf[9] << 16) | (buf[10] << 8) | buf[11];
				count1 = len / 2048;
				count2 = len % 2048;
				eflash_addr = ((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]);
				
				for(i = 0; i < count1; i++)
				{
					LT_ReadFlash_DMA(rebuf,eflash_addr + 2048 * i,2048);
					File_CRC = GetCrc32(rebuf,2048,File_CRC);
				}
				
				if(count2 > 0)
				{
					LT_ReadFlash_DMA(rebuf,eflash_addr + 2048 * i,count2);
					File_CRC = GetCrc32(rebuf,count2,File_CRC);
				}

				if (CRC_Enable_Flag && CRC_Feedback_Flag) // CRC feedback is the default
				{
					rebuf[5] = cmd;
					rebuf[6] = buf[4];
					rebuf[7] = buf[5];
					rebuf[8] = buf[6];
					rebuf[9] = buf[7];
					rebuf[10] = (File_CRC >> 24) & 0xFF;
					rebuf[11] = (File_CRC >> 16) & 0xFF;
					rebuf[12] = (File_CRC >> 8) & 0xFF;
					rebuf[13] = File_CRC & 0xFF;
					
					LT_SendFlashData_CRC_Frame(rebuf, 9);
				}
			}
		}
		else // CRC NG
		{
			if (CRC_Feedback_Flag) // CRC feedback is the default
			{
				rebuf[3] = cmd;
				rebuf[4] = 0x00;
				LT_SendData_CRC_Frame(rebuf, 2);
			}
		}
	}
	
	gHidRx.Flag = 0;
	gHidRx.Count = 0; // Clear to receive the next data
	//LT_ClearRxBuf();	// Clear receive buffer
}

#endif

void Var_AddrRemapping(uint16_t *addr)     // reg address mapping to var array
{
#if (VAR_REG_S == 0x7000)
	if (*addr >= VAR_REG_S && *addr <= VAR_REG_E) 
		*addr -= 0x5000;
#endif
//	if (*addr > (VAR_ADDR_E + 0xFF))
//		*addr = 0;
//	;
}

void Var_AddrToReg(uint8_t *buf)         // var array mapping to reg address
{
	uint16_t addr = (buf[0]<<8)|(buf[1]);

	if((addr >= VAR_ADDR_S && addr <= VAR_ADDR_E)) 
	{
		addr += 0x5000;
		buf[0] = (addr>>8)&0xFF;
		buf[1] = addr&0xFF;
	}
}

uint8_t CoordinateChangeToBox(int16_t *x, int16_t *y, int16_t *w, int16_t *h, uint8_t alignment, _PICINFO pic, uint8_t mix)
{ 
	if(mix == 0)
	{   //������
		if (alignment == 0)
		{
			if (*x + *w > LCD_XSIZE_TFT)
				*w = LCD_XSIZE_TFT - *x;
		}
		else if (alignment == 1)
		{
			
		}
		else if (alignment == 2)
		{
			
		}
	}
	else if(mix == 1)
	{
		if (alignment == 0)
		{
			if (*x < pic.x)
				*x = pic.x;
			if (*x + *w > pic.x + pic.w)
				*w = pic.x + pic.w - *x;
			if (*y < pic.y)
				*y = pic.y;
			if (*y + *h > pic.y + pic.h)
				*h = pic.y + pic.h - *y;
		}
		else if (alignment == 2)
		{
		}
	}

	return 0;
}

/********************************************************************************
 * Function Name : reg_operation
 * Description   : Operation register.
 * Input         : - addr: register address
 * Output        : None
 * Return        : None
 *********************************************************************************/
void reg_operation(uint16_t addr)
{
	if (addr == VAR_PAGE)
	{
		if (pic_id != (var[VAR_PAGE * 2] << 8) + var[VAR_PAGE * 2 + 1])
		{
			Display_page((var[VAR_PAGE * 2] << 8) + var[VAR_PAGE * 2 + 1]);
		}
	}
	else if (addr == VAR_BL)
	{
		if (var[VAR_BL * 2 + 1] > 63)
			var[VAR_BL * 2 + 1] = 63;

		LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
		Backlight_flag = 1;
//		if (Auto_Backlight)
//		{
//			Backlight_count = 0;
//			Backlight_flag = 1;
//		}
	}
	else if (addr == VAR_TIMESET) // time setting
	{
		RTC_Get();

		if (var[VAR_TIMESET * 2 + 1] == 1)
		{
			var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
			var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
			var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		}
		else if (var[VAR_TIMESET * 2 + 1] == 2)
		{
			var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
			var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
			var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
			var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		}
		else if (var[VAR_TIMESET * 2 + 1] == 3)
		{
			var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
			var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
			var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
			var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		}
		else if (var[VAR_TIMESET * 2 + 1] == 4)
		{
			var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
			var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
			var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
		}
		else if (var[VAR_TIMESET * 2 + 1] == 5)
		{
			var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
			var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
			var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
			var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		}
		else if (var[VAR_TIMESET * 2 + 1] == 6)
		{
			var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
			var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
			var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
			var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
		}

		RTC_Set(2000 + var[(VAR_TIME + 0) * 2 + 1], var[(VAR_TIME + 1) * 2 + 1], var[(VAR_TIME + 2) * 2 + 1], var[(VAR_TIME + 3) * 2 + 1], var[(VAR_TIME + 4) * 2 + 1], var[(VAR_TIME + 5) * 2 + 1]);
	}
	else if (addr == VAR_WAV)
	{
		Wav_DAC_Init((var[VAR_WAV * 2] << 8) + var[VAR_WAV * 2 + 1]);
	}
	else if (addr == VAR_VOLUME)
	{
		if (var[2 * VAR_VOLUME + 1] > 16)
			wav_reduce_para = 16;
		else
			wav_reduce_para = var[2 * VAR_VOLUME + 1];
	}
	else if (addr == VAR_KEY)
	{
		Button_Key_Code = (var[VAR_KEY * 2] << 8) | var[VAR_KEY * 2 + 1];
		Button_Key_Code_Flag = 1;
	}
	else if (addr == VAR_BLAUTO)
	{
		if(var[2 * VAR_BLAUTO + 1] == 1)
		{
			if (Backlight_flag == 0)
			{	
				Backlight_count = 0;								
				Backlight_flag = 1;
				LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
			}
		}
		else if (var[2 * VAR_BLAUTO + 1] == 0)
		{
			Backlight_count = 0;								
			Backlight_flag = 0;
			LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
		}
	}
	else if (addr == VAR_BLSLEEP)
	{
//		if (Backlight_flag == 0 && var[2 * VAR_BLAUTO + 1] == 1)
//		{
//			LT_BacklightSet(gDutyBuf[var[VAR_BLSLEEP * 2 + 1]]);
//		}
	}
	else if (addr == VAR_MTLANGUAGE)
	{
		if (var[2 * VAR_MTLANGUAGE + 1] < multi_language_count && var[2 * VAR_MTLANGUAGE + 1] != multi_language)
		{
			uint8_t language_buff[2048];
			uint32_t language_sum = 0,language_count = 0,L_count = 0;
			uint32_t language_addr = 0,L_addr,L_len = 0;
			uint16_t L_num;
			multi_language = var[2 * VAR_MTLANGUAGE + 1];
			
			LT_ReadFlash_UI(language_buff,addr_index[18] + 8 * multi_language,8);
			language_addr = (language_buff[0]) + (language_buff[1] << 8) + (language_buff[2] << 16) + (language_buff[3] << 24);
			language_sum = (language_buff[4]) + (language_buff[5] << 8) + (language_buff[6] << 16) + (language_buff[7] << 24);

			if (language_sum - language_count >=2048)
					LT_ReadFlash_UI(language_buff,language_addr,2048);
			else 
				LT_ReadFlash_UI(language_buff,language_addr,language_sum);
			
			while(1)
			{
				if (L_count + 4 > 2048)
				{
					if (language_sum - language_count >= 2048)
						LT_ReadFlash_UI(language_buff,language_addr + language_count,2048);
					else 
						LT_ReadFlash_UI(language_buff,language_addr + language_count,language_sum);
					L_count = 0;
						
				}
				L_addr = language_buff[L_count] + (language_buff[L_count + 1] << 8);
				L_len = language_buff[L_count + 2] + (language_buff[L_count + 3] << 8);
				L_count = L_count + 4;
				
				if(L_count + L_len > 2048)
				{
					if (language_sum - (language_count + 4) >= 2048)
						LT_ReadFlash_UI(language_buff,language_addr + language_count + 4,2048);
					else 
						LT_ReadFlash_UI(language_buff,language_addr + language_count + 4 ,language_sum - (language_count + 4));
					L_count = 0;
				}
				
				for (uint16_t ll = 0; ll < L_len; ll++)
				{
					var[L_addr * 2 + ll] = language_buff[L_count + ll];
				}
				language_count += L_len + 4;
				L_count += L_len;
				
				if(language_count >= language_sum)
					break;
			}
			
			if(Pop_up_flag == 1)
			{
				Display_pop_up(Pop_up_id,Pop_up_x,Pop_up_y);
			}
			else Display_page(pic_id);
		}
		else
			var[2 * VAR_MTLANGUAGE + 1] = multi_language;
	}
	else if (addr == VAR_UI_CHANGE)
	{
		if(lt_screen_dir != var[VAR_UI_CHANGE * 2 + 1])
			LT_LCD_screen_dir(var[VAR_UI_CHANGE * 2 + 1]);
	}
	else if (addr == VAR_ENCODER_C)
	{

		
	}
	
}

uint8_t pic_id_page;
uint8_t pic_encoder_page;
/***********************************************************************************
 * Function Name : Display_page
 * Description   : Display the interface of a page.
 * Input         : - id: Page No
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Display_page(uint16_t id)
{
	
	if (id < addr_index[7])
	{
		uint8_t buff[12] = {0};

		var[VAR_PAGE * 2 + 0] = id >> 8;
		var[VAR_PAGE * 2 + 1] = id & 0xFF;

		LT_ReadFlash_UI(buff, addr_index[6] + 12 * id, 12);
		pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
		pic_w = buff[4] + (buff[5] << 8);
		pic_h = buff[6] + (buff[7] << 8);
		pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
		pic_flag = buff[11];
		pic_id = id;
		
		EFLASH_Init(g_sys_clk / 1000);
		EFLASH_SetWritePermission();
		W_buff[0] = pic_id;
		Ye_Mian_num = pic_id;
		EFLASH_Write(flh_sAddr, &W_buff[0], 1);	
		EFLASH_ClrWritePermission();	
		
		//printf("/***********pic_id:%d/\n",pic_id);
		
//////////////////////////////////////20240607
	/*	pic_id_page = id;
		if(pic_id_page == 2)
		{
			pic_encoder_page = 2;
		}
		if(pic_id_page == 3)
		{
			pic_encoder_page = 3;
		}
		if(pic_id_page == 1)
		{
			pic_encoder_page = 1;
		}
		if(pic_id_page == 9)
		{
			pic_encoder_page = 9;
		}*/
///////////////////////////////////////

		FullScreen_addr = pic_add;
		FullScreen_color = pic_len;
		FullScreen_flag = pic_flag;       //set 0
//		LCD_XSIZE_TFT = pic_w;       //
//		LCD_YSIZE_TFT = pic_h;       //

		// debug
//		 printf("page id: %d , page info: %d  %d  %d   %d  0x%x     \r\n",id,pic_w,pic_h,pic_len,pic_flag,pic_add);

		/*Clear previous page key function*/
//		Button_Key_Code_Flag = 0;
//		Button_Key_Code = 0;

		Basci_count = 0;
		Basci_flag = 0;
		Ges_sc_flag = 0;
		Adj_count = 0;
		Adj_flag = 0;

		Slide_count = 0;
		Slide_flag = 0;

		Dio_count = 0;
		Dio_flag = 0;
		DioKb_flag = 0;
		Aio_count = 0;
		AioKb_flag = 0;
		Aio_flag = 0;
		GBKio_count = 0;
		GBKioKb_flag = 0;
		GBKio_flag = 0;
		Kb_count = 0;
		Kb_flag = 0;

		sldmenu_count = 0;
		sldmenu_flag = 0;

		VarKey_count = 0;
		VarKey_flag = 0;

		Pop_up_count = 0;
		Pop_up_flag = 0;
		button_Press_flag = 0;
		Gesture_press = 0;
		/**************/

		/*Clear the dynamic display function on the previous page*/
		data_D_num = 0;
		memset(data_D_w, 0, sizeof(data_D_w));

		pdata_D_num = 0;
		memset(pdata_D_w, 0, sizeof(pdata_D_w));
		Var_Count_num = 0; 
		Gif_num = 0;
		RTC_num = 0;
		Clock_num = 0;
		Scroll_num = 0;
		Gesture_flag = 0;
		RingSld_count = 0;
		curve_num = 0;
		gEncoderFlag = 0;
		knob_flag = 0;
		var[VAR_ENCODER_C * 2 + 1] = 0;
		Pointer_Count_flag = 0;
		Pointer_Count_num = 0;
		
		Saving_counting_parameters(); // Save data for time counter
		Count_sum = 0;

#if (UARTBUS_OPTION == 2)
		if (gUsartTx.Mode == 0x02)
			tx_repeat_flag = 0;
#endif
		if (gWavFlag == 1 || gWavType == 1)
		{
			gWavType = 0;
			close_wav_dac();
		}

		RTC_Get();
		var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
		var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
		var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
		var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
		var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
		var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		var[VAR_TIMESET * 2 + 1] = calendar.week;

		// if (pic_flag == 0x10) // pure color
		// {
		// 	LT268_TFT_FillColor(0, 0, LCD_XSIZE_TFT, LCD_YSIZE_TFT, pic_len);
		// }
	    // else if (pic_len != 0 && pic_flag != 0xFF)
		// {
		// 	LT268_TFT_ShowPicture(0, 0, pic_w, pic_h, pic_add);
		// }
		if (pic_flag == 0x10 || (pic_len != 0 && pic_flag != 0xFF))
			LT_ShowPicture(0, 0, pic_w, pic_h, pic_add, pic_len, pic_flag); 

		Get_date_variable_Id(id);
		Get_Touch_info(id);
	}
}

/***********************************************************************************
* Function Name : Display_pop_up
* Description   : Show pop-up page.
* Input         : - id: page id
				  - x,y: Screen coordinates
* Output        : None
* Return        : None
************************************************************************************/
void Display_pop_up(uint16_t id, uint16_t x, uint16_t y)
{
	if (id < addr_index[7])
	{
		uint8_t buff[12] = {0};
		uint16_t w, h;
		uint8_t bgflag = 0;

		LT_ReadFlash_UI(buff, addr_index[6] + 12 * id, 12);
		pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
		pic_w = buff[4] + (buff[5] << 8);
		pic_h = buff[6] + (buff[7] << 8);
		pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
		pic_flag = buff[11];
		pic_id = id;
		w = pic_w;
		h = pic_h;

		var[VAR_PAGE * 2 + 0] = pic_id >> 8;
		var[VAR_PAGE * 2 + 1] = pic_id & 0xFF;
		
		// debug
//		printf("Display_pop_up: xy %d  %d   wh %d  %d  %d   %d  0x%x     \r\n",x,y,pic_w,pic_h,pic_len,pic_flag,pic_add);

		Page_VirAddr = pic_add;
		Page_VirLen = pic_len;
		Page_VirFlag = pic_flag;   // set 0 
		Page_VirW = pic_w;
		Page_VirH = pic_h;

		if (pic_len != 0 && pic_flag != 0xFF)
		{
			if ((gPop_up_Info[Pop_up_num].function & 0x01) == 1) // bokeh background
			{
				bgflag = 1;
			}
			
			if (pic_flag == ColorPure || pic_flag == ColorRGB565)
			{
				LT_ShowPicture(x, y, pic_w, pic_h, pic_add, pic_len, pic_flag);
			}
			else if (pic_flag == ColorARGB0565 || pic_flag == ColorARGB4444)
			{
				//��ͼ
				LT268_pic_to_buffer(0,0,pic_w,m_PngData,
						x,y,LCD_XSIZE_TFT,FullScreen_addr,
						pic_w,pic_h,FullScreen_flag);
				LT268_pic_to_buffer(0,0,pic_w,m_PngData,
						0,0,pic_w,pic_add,
						pic_w,pic_h,pic_flag);
				LT268_buffer_to_TFT(0,0,pic_w,m_PngData,
					x,y,pic_w,pic_h);
			}
		}

		/*Clear previous page key function*/
//		Button_Key_Code_Flag = 0;
//		Button_Key_Code = 0;

		Basci_count = 0;
		Basci_flag = 0;
		Ges_sc_flag = 0;
		Adj_count = 0;
		Adj_flag = 0;

		Slide_count = 0;
		Slide_flag = 0;

		Dio_count = 0;
		Dio_flag = 0;
		DioKb_flag = 0;
		Aio_count = 0;
		AioKb_flag = 0;
		Aio_flag = 0;
		GBKio_count = 0;
		GBKioKb_flag = 0;
		GBKio_flag = 0;
		Kb_count = 0;
		Kb_flag = 0;

		Kb_count = 0;
		Kb_flag = 0;

		sldmenu_count = 0;
		sldmenu_flag = 0;

		VarKey_count = 0;
		VarKey_flag = 0;

		button_Press_flag = 0;
		Gesture_press = 0;
		/**************/

		/*Clear the dynamic display function on the previous page*/
		data_D_num = 0;
		memset(data_D_w, 0, sizeof(data_D_w));

		pdata_D_num = 0;
		memset(pdata_D_w, 0, sizeof(pdata_D_w));

		Var_Count_num = 0; 
		Gif_num = 0;
		RTC_num = 0;
		Clock_num = 0;
		Scroll_num = 0;
		Gesture_flag = 0;
		RingSld_count = 0;
		Saving_counting_parameters();
		Count_sum = 0;
		gWavType = 0;
		knob_flag = 0;
		var[VAR_ENCODER_C * 2 + 1] = 0;
		Pointer_Count_flag = 0;
		Pointer_Count_num = 0;
		
#if (UARTBUS_OPTION == 2)
		if (gUsartTx.Mode == 0x02)
			tx_repeat_flag = 0;
#endif

		RTC_Get();
		var[(VAR_TIME + 0) * 2 + 1] = calendar.w_year - 2000;
		var[(VAR_TIME + 1) * 2 + 1] = calendar.w_month;
		var[(VAR_TIME + 2) * 2 + 1] = calendar.w_date;
		var[(VAR_TIME + 3) * 2 + 1] = calendar.hour;
		var[(VAR_TIME + 4) * 2 + 1] = calendar.min;
		var[(VAR_TIME + 5) * 2 + 1] = calendar.sec;
		var[VAR_TIMESET * 2 + 1] = calendar.week;

		Get_date_variable_Id(id);
		Get_Touch_info(id);
		Wav_DAC_Init((var[VAR_WAV * 2] << 8) + var[VAR_WAV * 2 + 1]);
	}
}

/***********************************************************************************
* Function Name	: Display_Icon
* Description	: Show a icon.
* Input			: - id: icon id
				  - x,y: Screen coordinates
* Output        : None
* Return        : None
************************************************************************************/
void Display_Icon(uint16_t id, uint16_t x, uint16_t y, uint8_t Display_mode)
{
	uint8_t buff[12] = {0};

	LT_ReadFlash_UI(buff, addr_index[10] + 12 * id + multi_language * 12 * addr_index[11], 12);
	pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
	pic_w = buff[4] + (buff[5] << 8);
	pic_h = buff[6] + (buff[7] << 8);
	pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
	pic_flag = buff[11];

//  debug
//	printf("Display_Icon  %d  %d  %d  %d  x%x , pic_flag %d   Display_mode %d  \r\n",x,y,pic_w,pic_h,pic_add,pic_flag,Display_mode);
		
	if (pic_len != 0 && pic_flag != 0xFF)
	{
		if ((pic_flag >= 0 && pic_flag < 5) || pic_flag == ColorARGB8565)
		{
			if(Display_mode == 0)
				LT_ShowPicture(x, y, pic_w, pic_h, pic_add, pic_len, pic_flag); 
			else
			{
				LT_BG_IOCNID = id;
				LT_getBackGround(x, y, pic_w, pic_h, m_PngData,PIC_ON_LCDImg);
				LT268_pic_to_buffer(0,0,pic_w,m_PngData,
									0,0,pic_w,pic_add,
									pic_w, pic_h,pic_flag);
				LT268_buffer_to_TFT(0,0,pic_w,m_PngData,
									x, y, pic_w, pic_h);
			}
		}
	}
	

}

/***********************************************************************************
* Function Name : icon_display
* Description   : Show a icon.
* Input         : - type: icon info sources
				  - buff: icon info
* Output        : None
* Return        : None
************************************************************************************/
void icon_display(uint8_t type, uint8_t *buff)
{
	uint16_t p_add, p_len, pointer;
	uint16_t x, y, w, h;
	uint16_t simage, eimage, nimage;
	uint16_t s_num, e_num;
	uint16_t d_num;
	uint8_t buff1[12] = {0}, i;
	uint8_t Display_Mode = 0;

	if (type == 0) // instruction information source is configuration file
	{
		Display_Mode = (buff[4] & 0x80) >> 7;
		p_add = (buff[5] + (buff[6] << 8));
		x = buff[7] + (buff[8] << 8);
		y = buff[9] + (buff[10] << 8);
		simage = buff[11] + (buff[12] << 8);
		eimage = buff[13] + (buff[14] << 8);
		s_num = buff[15] + (buff[16] << 8);
		e_num = buff[17] + (buff[18] << 8);
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		Display_Mode = (var[pointer]& 0x80) >> 7;
		p_add = (var[pointer + 1] + (var[pointer + 2] << 8));
		x = var[pointer + 3] + (var[pointer + 4] << 8);
		y = var[pointer + 5] + (var[pointer + 6] << 8);
		simage = var[pointer + 7] + (var[pointer + 8] << 8);
		eimage = var[pointer + 9] + (var[pointer + 10] << 8);
		s_num = var[pointer + 11] + (var[pointer + 12] << 8);
		e_num = var[pointer + 13] + (var[pointer + 14] << 8);
	}

	Var_AddrRemapping(&p_add);
	
	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
	}
	
	if(Display_Mode==0)	Display_Mode = PIC_ON_BaseImg;
	else if(Display_Mode==1) Display_Mode = PIC_ON_LCDImg;
	else Display_Mode = PIC_ON_BaseImg;

	
	nimage = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
	if (nimage >= s_num && nimage <= e_num)
	{
		d_num = simage + nimage - s_num;
		Display_Icon(d_num, x, y, Display_Mode);
	}
	else
	{
		
		LT_ReadFlash_UI(buff1, addr_index[10] + 12 * simage + multi_language * 12 * addr_index[11], 12);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		if(Display_Mode == 0)
		{
			LT268_dispaly_CutPicture(x, y,
									 x, y, pic_w, pic_h,
									 LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
		}
		else
		{
			LT_getBackGround(x,y,pic_w,pic_h,m_PngData,PIC_ON_LCDImg);
			LT268_buffer_to_TFT(0,0,pic_w,m_PngData,
								x,y,pic_w, pic_h);
		}
		
	}

}


/***********************************************************************************
* Function Name : bit_control
* Description   : control variable's bit.
* Input			: - type: icon info sources
				  - buff: icon info
* Output        : None
* Return        : None
************************************************************************************/
void bit_control(uint8_t type, uint8_t *buff)
{
	uint16_t p_add, pointer;
	uint16_t x, y;
	uint16_t simage, eimage, nimage;
	uint8_t control_bit, Display_mode;
	uint8_t buff1[12] = {0};
	uint8_t Display_Mode = 0;

	if (type == 0) // instruction information source is configuration file
	{
		Display_Mode = (buff[4] & 0x80) >> 7;
		p_add = (buff[5] + (buff[6] << 8));
		x = buff[7] + (buff[8] << 8);
		y = buff[9] + (buff[10] << 8);
		control_bit = buff[11];
		simage = buff[12] + (buff[13] << 8);
		eimage = buff[14] + (buff[15] << 8);
		Display_mode = buff[16];
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		Display_Mode = (var[pointer] & 0x80) >> 7;
		p_add = (var[pointer + 1] + (var[pointer + 2] << 8));
		x = var[pointer + 3] + (var[pointer + 4] << 8);
		y = var[pointer + 5] + (var[pointer + 6] << 8);
		control_bit = var[pointer + 7];
		simage = var[pointer + 8] + (var[pointer + 9] << 8);
		eimage = var[pointer + 10] + (var[pointer + 11] << 8);
		Display_mode = var[pointer + 12];
	}

	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
	}

	nimage = (var[p_add * 2] << 8) + var[p_add * 2 + 1];

	if ((nimage & (0x01 << control_bit)) == 0)
	{
		Display_Icon(simage, x, y, Display_Mode);
	}
	else
	{
		Display_Icon(eimage, x, y, Display_Mode);
	}
}

/*******************************************************************************
 * Function Name : LT_Print_zk_Font
 * Description   : Display a string.
 * Input         :
 * Output        : None
 * Return        : None
 ********************************************************************/
uint16_t LT_Print_zk_Font(
	uint16_t encode // encoding type, 0:GB2312  1:GBK  2:BIG5  3:UNICODE  4:ASCII
	,
	uint32_t FlashAddr // Font source address(exSpiFlash)
	,
	uint32_t ShowAddr // Displays the address of the layer
	,
	uint16_t width // Display the width of the layer
	,
	uint8_t W_Size // font width
	,
	uint8_t H_Size // font height
	,
	uint8_t Alignment // Alignment
	,
	uint32_t FontColor // The foreground color of the font
	,
	uint32_t BackColor // The background color of the font
	,
	uint8_t enbackcolor // Background color enable, 0:disable  1:enable
	,
	uint8_t mix // mix mode, 0:with fullscreen interface   1:with specific pictures(Text box needs to be fully included)
	,
	_PICINFO mixpic // mix picture info
	,
	uint8_t text_mode // text display mode: 0:txt  1:encryption use '*' (0x2A)
	,
	uint16_t Xs // Text box start x position
	,
	uint16_t Ys // Text box start Y position
	,
	uint16_t Xe // Text box end x position
	,
	uint16_t Ye // Text box end y position
	,
	uint8_t dis_x // The interval between two adjacent fonts on the x-axis
	,
	uint8_t dis_y // The interval between two adjacent fonts on the y-axis
	,
	uint8_t *c // Address of text
	,
	uint16_t len_max // max lenght of text
)
{
	uint32_t i = 0, j = 0;
	uint16_t X_start = 0, Y_start = 0;
	uint16_t box_w = Xe - Xs + 1, box_h = Ye - Ys + 1;
	uint8_t gray, gray_bit;
	uint16_t row = 0, row_num = 0, row_w[100]; // max line = 100
	uint16_t disp_w = 0, disp_i = 0,temp_w;
	uint8_t unicode_w;
	uint16_t font_byte; // bytes of a single font
//	uint16_t dis_w;

	LT_ReadFlash_UI(Ascii_w, FlashAddr + 9, 95);
	LT_ReadFlash_UI(&gray, FlashAddr + 8, 1);

	if (gray == 0)
		gray_bit = 1;
	else if (gray == 1)
		gray_bit = 2;
	else if (gray == 2)
		gray_bit = 4;

	if (encode == 4) // ASCII
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = (Ascii_w[c[i] - 0x20] + dis_x + 2);
			else if (c[i] == 0x0A)
				temp_w = 0; // newline
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if ((Y_start + H_Size) > box_h)
					break; // Text box Y-axis is out of range

				data_w = disp_w; // Record width
				Y_start += H_Size;
				disp_w = 0;
				row_w[row_num++] = disp_w;

				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
				{
					i++;
					j++;
				}

			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
				j++;
			}
		}
	}
	else if (encode == 0) // GB2312
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
				temp_w = W_Size + dis_x;
			else if (c[i] == 0x0A)
				temp_w = 0; // newline
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if ((Y_start + H_Size) > box_h)
					break; // Text box Y-axis is out of range

				data_w = disp_w; // Record width
				Y_start += H_Size;
				row_w[row_num++] = disp_w;
				disp_w = 0;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
				{
					i++;
					j++;
				}
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
				j++;
			}
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
				j++;
			}
		}
	}
	else if (encode == 1) // GBK
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
				temp_w = W_Size + dis_x;
			else if (c[i] == 0x0A)
				temp_w = 0; // newline
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((disp_w + temp_w) > (Xe - Xs + 1) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if ((Y_start + H_Size) > box_h)
					break; // Text box Y-axis is out of range

				data_w = disp_w; // Record width
				Y_start += H_Size;
				row_w[row_num++] = disp_w;
				disp_w = 0;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
				{
					i++;
					j++;
				}
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
				j++;
			}
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
				j++;
			}
		}
	}
	else if (encode == 2) // BIG5
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
				temp_w = W_Size + dis_x;
			else if (c[i] == 0x0A)
				temp_w = 0; // newline
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if ((Y_start + H_Size) > box_h)
					break; // Text box Y-axis is out of range

				data_w = disp_w; // Record width
				Y_start += H_Size;
				row_w[row_num++] = disp_w;
				disp_w = 0;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
				{
					i++;
					j++;
				}
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
				j++;
			}
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
				j++;
			}
		}
	}
	else if (encode == 3) // UNICODE
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode == 0x0000)
				len_max = i;
			else if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode >= start_code && unicode <= end_code)
				temp_w = W_Size + dis_x;
			else if (unicode == 0x000A)
				temp_w = 0; // newline
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if ((Y_start + H_Size) > box_h)
					break; // Text box Y-axis is out of range

				data_w = disp_w; // Record width
				Y_start += H_Size;
				row_w[row_num++] = disp_w;
				disp_w = 0;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
				{
					i += 2;
					j++;
				}
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
				j++;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
				j++;
			}
		}
	}
	else if (encode == 6) // UNICODE
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];
				
		font_byte = (W_Size * gray_bit + 7) / 8 * H_Size;

		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode == 0x0000)
				len_max = i;
			else if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode >= start_code && unicode <= end_code)
			{
				LT_ReadFlash_UI(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - start_code) * (font_byte + 1), 1);
				temp_w = unicode_w + dis_x;
			}
			else if (unicode == 0x000A)
				temp_w = 0; // newline
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if ((Y_start + H_Size) > box_h)
					break; // Text box Y-axis is out of range

				data_w = disp_w; // Record width
				Y_start += H_Size;
				row_w[row_num++] = disp_w;
				disp_w = 0;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
				{
					i += 2;
					j++;
				}
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += temp_w;
				i += 2;
				j++;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += temp_w;
				i += 2;
				j++;
			}
		}
	}
	if (row_num * H_Size > box_h)
		row_num = box_h / H_Size;
	// printf("row_num  %d   Ys  %d \r\n",row_num,Ys);     //debug
	if (row_num == 0)
		return 0;
	
	if(text_mode==2) return data_w; // display width

	if (text_mode == 1)
    {
        c = (uint8_t *)Display_buff_temp;
        if(encode == 3 || encode ==6)
        {
            for (i = 0; i < j; i++)
            {
                c[i * 2 ] = 0x00;
                c[i * 2 + 1] = 0x2a;
            }
            len_max = j * 2;
        }
        else
        {
            for (i = 0; i < j; i++)
            {
                c[i] = 0x2a;
            }
            len_max = j;
        }

        data_w = (Ascii_w['*' - 0x20] + dis_x + 2)*j; // Record width
//        disp_w = data_w;
    }
	
	i = 0;
	disp_w = 0;

	if (Alignment == 0) // Align Left Center
	{
		X_start = Xs;
		Y_start = Ys + (box_h - row_num * H_Size) / 2;
	}
	else if (Alignment == 3) // Align Left Up
	{
		X_start = Xs;
		Y_start = Ys;
	}
	else if (Alignment == 6) // Align left lower
	{
		X_start = Xs;
		Y_start = Ye - row_num * H_Size;
	}
	else if (Alignment == 1) // Center Align Center
	{
		X_start = 0;
		Y_start = Ys + (box_h - row_num * H_Size) / 2;
	}
	else if (Alignment == 4) // Center Align Up
	{
		X_start = 0;
		Y_start = Ys;
	}
	else if (Alignment == 7) // Center Align lower
	{
		X_start = 0;
		Y_start = Ye - row_num * H_Size;
	}
	else if (Alignment == 2) // Align right Center
	{
		X_start = 0;
		Y_start = Ys + (box_h - row_num * H_Size) / 2;
	}
	else if (Alignment == 5) // Align right Up
	{
		X_start = 0;
		Y_start = Ys;
	}
	else if (Alignment == 8) // Align right lower
	{
		X_start = 0;
		Y_start = Ye - row_num * H_Size;
	}

	if (Y_start != Ys)
	{
		if (!enbackcolor)
		{
			if (mix == 0)
			{
				if(ShowAddr == PIC_ON_LCDImg)
				{
					LT_getBackGround(Xs, Ys, box_w, Y_start - Ys, m_PngData,PIC_ON_LCDImg);
					LT268_buffer_to_TFT(0,0,box_w,m_PngData,
										Xs, Ys, box_w, Y_start - Ys);
				}
				else
					LT268_dispaly_CutPicture(Xs, Ys,
						Xs, Ys, box_w, Y_start - Ys,
						LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
			}
			else if(mix == 1)
				LT268_dispaly_CutPicture(Xs, Ys,
					Xs - mixpic.x, Ys - mixpic.y, box_w, Y_start - Ys,
					mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
		}
		else
			LT268_TFT_FillColor(Xs, Ys, box_w, Y_start - Ys, BackColor);
	}

	// display
	if (encode == 4) // ASCII
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = (Ascii_w[c[i] - 0x20] + dis_x + 2);
			else if (c[i] == 0x0A)
				temp_w = 0; // newline

			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (++row > row_num)
					break; // Text box Y-axis is out of range

				// Show the front background of one line
				if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
				{
					X_start = Xs;
				}
				else if (Alignment == 2 || Alignment == 5 || Alignment == 8) // right
				{
					X_start = Xe - disp_w + 1;
					if (X_start > Xs)
					{
						if (!enbackcolor)
						{
							if (mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(Xs, Y_start, X_start - Xs, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,X_start - Xs,m_PngData,
														Xs, Y_start, X_start - Xs, H_Size);
								}
								else
									LT268_dispaly_CutPicture(Xs, Y_start,
										Xs, Y_start, X_start - Xs, H_Size,
										LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix == 1)
								LT268_dispaly_CutPicture(Xs, Y_start,
									Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size,
									mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}
				else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
				{
					X_start = Xs + (box_w - disp_w) / 2;
					if (disp_w < box_w)
					{
						if (!enbackcolor)
						{
							if (mix == 0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(Xs, Y_start, X_start - Xs, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,X_start - Xs,m_PngData,
														Xs, Y_start, X_start - Xs, H_Size);
								}
								else
									LT268_dispaly_CutPicture(Xs, Y_start,
										Xs, Y_start, X_start - Xs, H_Size,
										LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix == 1)
								LT268_dispaly_CutPicture(Xs, Y_start,
									Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size,
									mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}

				// display
				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{
						LT268_GrayScaleFont_dislay(4, ShowAddr, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i]);

						X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else
						disp_i++;
				}

				// Show the remaining background of one line
				if (disp_w < box_w)
				{
					if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
					{
						if (!enbackcolor)
						{
							if (mix == 0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(X_start, Y_start, Xe - X_start + 1, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,Xe - X_start + 1,m_PngData,
														X_start, Y_start, Xe - X_start + 1, H_Size);
								}
								else
									LT268_dispaly_CutPicture(X_start, Y_start,
										X_start, Y_start, Xe - X_start + 1, H_Size,
										LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix == 1)
								LT268_dispaly_CutPicture(X_start, Y_start,
									X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size,
									mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
					// else if(Alignment == 2)		LT268_dispaly_CutPicture(Xs,Y_start,Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
					{
						if (!enbackcolor)
						{
							if(mix == 0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(X_start, Y_start, Xe - X_start + 1, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,Xe - X_start + 1,m_PngData,
														X_start, Y_start, Xe - X_start + 1, H_Size);
								}
								else
									LT268_dispaly_CutPicture(X_start, Y_start,
										X_start, Y_start, Xe - X_start + 1, H_Size,
										LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix == 1)
								LT268_dispaly_CutPicture(X_start, Y_start, 
								X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, 
								mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
				}
				// data_w = disp_w;  //Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
		}
	}
	else if (encode == 0) // GB2312
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
				temp_w = W_Size + dis_x;
			else if (c[i] == 0x0A)
				temp_w = 0;

			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (++row > row_num)
					break; // Text box Y-axis is out of range

				// Show the front background of one line
				if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
				{
					X_start = Xs;
				}
				else if (Alignment == 2 || Alignment == 5 || Alignment == 8) // right
				{
					X_start = Xe - disp_w + 1;
					if (X_start > Xs)
					{
						if (!enbackcolor)
						{
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(Xs, Y_start, X_start - Xs, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,X_start - Xs,m_PngData,
														Xs, Y_start, X_start - Xs, H_Size);
								}
								else
									LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
									LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}
				else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
				{
					X_start = Xs + (box_w - disp_w) / 2;
					if (disp_w < box_w)
					{
						if (!enbackcolor)
						{
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(Xs, Y_start, X_start - Xs, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,X_start - Xs,m_PngData,
														Xs, Y_start, X_start - Xs, H_Size);
								}
								else
									LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}

				// display
				for (; disp_i < i;)
				{

					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{
						LT268_GrayScaleFont_dislay(4, ShowAddr, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i]);

						X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0xa1 && c[disp_i] != 0xFF)
					{
						LT268_GrayScaleFont_dislay(encode, ShowAddr, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, W_Size + dis_x, &c[disp_i]);

						X_start += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				// Show the remaining background of one line
				if (disp_w < box_w)
				{
					if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
					{
						if (!enbackcolor)
						{
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(X_start, Y_start, Xe - X_start + 1, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,Xe - X_start + 1,m_PngData,
														X_start, Y_start, Xe - X_start + 1, H_Size);
								}
								else
								LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
					// else if(Alignment == 2)		LT268_dispaly_CutPicture(Xs,Y_start,Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
					{
						if (!enbackcolor)
						{ // LT268_dispaly_CutPicture(Xs,Y_start, Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(X_start, Y_start, Xe - X_start + 1, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,Xe - X_start + 1,m_PngData,
														X_start, Y_start, Xe - X_start + 1, H_Size);
								}
								else
								LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
				}
				// data_w = disp_w;  //Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 1) // GBK
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
				temp_w = W_Size + dis_x;
			else if (c[i] == 0x0A)
				temp_w = 0; // newline

			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (++row > row_num)
					break; // Text box Y-axis is out of range

				// Show the front background of one line
				if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
				{
					X_start = Xs;
				}
				else if (Alignment == 2 || Alignment == 5 || Alignment == 8) // right
				{
					X_start = Xe - disp_w + 1;
					if (X_start > Xs)
					{
						if (!enbackcolor)
						{
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(Xs, Y_start, X_start - Xs, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,X_start - Xs,m_PngData,
														Xs, Y_start, X_start - Xs, H_Size);
								}
								else
								LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}
				else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
				{
					X_start = Xs + (box_w - disp_w) / 2;
					if (disp_w < box_w)
					{
						if (!enbackcolor)
						{
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(Xs, Y_start, X_start - Xs, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,X_start - Xs,m_PngData,
														Xs, Y_start, X_start - Xs, H_Size);
								}
								else
									LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}

				// display
				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{
						LT268_GrayScaleFont_dislay(4, ShowAddr, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i]);

						X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0x81 && c[disp_i + 1] >= 0x40 && c[disp_i] != 0xFF)
					{
						LT268_GrayScaleFont_dislay(encode, ShowAddr, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, W_Size + dis_x, &c[disp_i]);

						X_start += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				// Show the remaining background of one line
				if (disp_w < box_w)
				{
					if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
					{
						if (!enbackcolor)
						{
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(X_start, Y_start, Xe - X_start + 1, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,Xe - X_start + 1,m_PngData,
														X_start, Y_start, Xe - X_start + 1, H_Size);
								}
								else
									LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
					// else if(Alignment == 2)		LT268_dispaly_CutPicture(Xs,Y_start,Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
					{
						if (!enbackcolor)
						{ // LT268_dispaly_CutPicture(Xs,Y_start, Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(X_start, Y_start, Xe - X_start + 1, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,Xe - X_start + 1,m_PngData,
														X_start, Y_start, Xe - X_start + 1, H_Size);
								}
								else
									LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
				}
				// data_w = disp_w;  //Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 2) // BIG5
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
				temp_w = W_Size + dis_x;
			else if (c[i] == 0x0A)
				temp_w = 0; // newline

			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (++row > row_num)
					break; // Text box Y-axis is out of range

				// Show the front background of one line
				if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
				{
					X_start = Xs;
				}
				else if (Alignment == 2 || Alignment == 5 || Alignment == 8) // right
				{
					X_start = Xe - disp_w + 1;
					if (X_start > Xs)
					{
						if (!enbackcolor)
						{
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(Xs, Y_start, X_start - Xs, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,X_start - Xs,m_PngData,
														Xs, Y_start, X_start - Xs, H_Size);
								}
								else
									LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}
				else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
				{
					X_start = Xs + (box_w - disp_w) / 2;
					if (disp_w < box_w)
					{
						if (!enbackcolor)
						{
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(Xs, Y_start, X_start - Xs, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,X_start - Xs,m_PngData,
														Xs, Y_start, X_start - Xs, H_Size);
								}
								else
									LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}

				// display
				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{
						LT268_GrayScaleFont_dislay(4, ShowAddr, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i]);

						X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0xa1 && c[disp_i + 1] >= 0x40)
					{
						LT268_GrayScaleFont_dislay(encode, ShowAddr, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, W_Size + dis_x, &c[disp_i]);

						X_start += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				// Show the remaining background of one line
				if (disp_w < box_w)
				{
					if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
					{
						if (!enbackcolor)
						{
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(X_start, Y_start, Xe - X_start + 1, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,Xe - X_start + 1,m_PngData,
														X_start, Y_start, Xe - X_start + 1, H_Size);
								}
								else
								LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
					// else if(Alignment == 2)		LT268_dispaly_CutPicture(Xs,Y_start,Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
					{
						if (!enbackcolor)
						{ // LT268_dispaly_CutPicture(Xs,Y_start, Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(X_start, Y_start, Xe - X_start + 1, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,Xe - X_start + 1,m_PngData,
														X_start, Y_start, Xe - X_start + 1, H_Size);
								}
								else
									LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
				}
				// data_w = disp_w;  //Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 3) // UNICODE
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode >= start_code && unicode <= end_code)
				temp_w = W_Size + dis_x;
			else if (unicode == 0x000A)
				temp_w = 0; // newline

			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (++row > row_num)
					break; // Text box Y-axis is out of range

				// Show the front background of one line
				if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
				{
					X_start = Xs;
				}
				else if (Alignment == 2 || Alignment == 5 || Alignment == 8) // right
				{
					X_start = Xe - disp_w + 1;
					if (X_start > Xs)
					{
						if (!enbackcolor)
						{
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(Xs, Y_start, X_start - Xs, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,X_start - Xs,m_PngData,
														Xs, Y_start, X_start - Xs, H_Size);
								}
								else
									LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}
				else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
				{
					X_start = Xs + (box_w - disp_w) / 2;
					if (disp_w < box_w)
					{
						if (!enbackcolor)
						{
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(Xs, Y_start, X_start - Xs, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,X_start - Xs,m_PngData,
														Xs, Y_start, X_start - Xs, H_Size);
								}
								else
									LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}

				// display
				for (; disp_i < i;)
				{
					unicode_temp = (c[disp_i] << 8) + c[disp_i + 1];
					if (unicode_temp < 128 && unicode_temp > 0x00)
					{
						LT268_GrayScaleFont_dislay(4, ShowAddr, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, Ascii_w[unicode_temp - 0x20] + dis_x + 2, &c[disp_i + 1]);

						X_start += (Ascii_w[unicode_temp - 0x20] + dis_x + 2);
						disp_i += 2;
					}
					else if (unicode_temp >= start_code && unicode_temp <= end_code)
					{
						LT268_GrayScaleFont_dislay(encode, ShowAddr, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, W_Size + dis_x, (uint8_t *)(unicode_temp - start_code));

						X_start += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i += 2;
				}

				// Show the remaining background of one line
				if (disp_w < box_w)
				{
					if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
					{
						if (!enbackcolor)
						{
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(X_start, Y_start, Xe - X_start + 1, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,Xe - X_start + 1,m_PngData,
														X_start, Y_start, Xe - X_start + 1, H_Size);
								}
								else
									LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
					// else if(Alignment == 2)		LT268_dispaly_CutPicture(Xs,Y_start,Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
					{
						if (!enbackcolor)
						{ // LT268_dispaly_CutPicture(Xs,Y_start, Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(X_start, Y_start, Xe - X_start + 1, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,Xe - X_start + 1,m_PngData,
														X_start, Y_start, Xe - X_start + 1, H_Size);
								}
								else
									LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
				}
				// data_w = disp_w;  //Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
					i += 2;
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 6) // UNICODE
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode >= start_code && unicode <= end_code)
			{
				LT_ReadFlash_UI(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - start_code) * (font_byte + 1), 1);
				temp_w = unicode_w + dis_x;
			}
			else if (unicode == 0x000A)
				temp_w = 0; // newline

			if ((disp_w + temp_w) > box_w || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (++row > row_num)
					break; // Text box Y-axis is out of range

				// Show the front background of one line
				if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
				{
					X_start = Xs;
				}
				else if (Alignment == 2 || Alignment == 5 || Alignment == 8) // right
				{
					X_start = Xe - disp_w + 1;
					if (X_start > Xs)
					{
						if (!enbackcolor)
						{
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(Xs, Y_start, X_start - Xs, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,X_start - Xs,m_PngData,
														Xs, Y_start, X_start - Xs, H_Size);
								}
								else
									LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}
				else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
				{
					X_start = Xs + (box_w - disp_w) / 2;
					if (disp_w < box_w)
					{
						if (!enbackcolor)
						{
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(Xs, Y_start, X_start - Xs, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,X_start - Xs,m_PngData,
														Xs, Y_start, X_start - Xs, H_Size);
								}
								else
									LT268_dispaly_CutPicture(Xs, Y_start, Xs, Y_start, X_start - Xs, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, X_start - Xs, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(Xs, Y_start, X_start - Xs, H_Size, BackColor);
					}
				}

				// display
				for (; disp_i < i;)
				{
					unicode_temp = (c[disp_i] << 8) + c[disp_i + 1];
					if (unicode_temp < 128 && unicode_temp > 0x00)
					{
						LT268_GrayScaleFont_dislay(4, ShowAddr, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, Ascii_w[unicode_temp - 0x20] + dis_x + 2, &c[disp_i + 1]);

						X_start += (Ascii_w[unicode_temp - 0x20] + dis_x + 2);
						disp_i += 2;
					}
					else if (unicode_temp >= start_code && unicode_temp <= end_code)
					{
						LT268_GrayScaleFont_dislay(encode, ShowAddr, FlashAddr, W_Size, H_Size, gray,
												   FontColor, BackColor, enbackcolor, mix, mixpic,
												   X_start, Y_start, W_Size + dis_x, (uint8_t *)(unicode_temp - start_code));

						LT_ReadFlash_UI(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode_temp - start_code) * (font_byte + 1), 1);
						X_start += (unicode_w + dis_x);
						disp_i += 2;
					}
					else
						disp_i += 2;
				}

				// Show the remaining background of one line
				if (disp_w < box_w)
				{
					if (Alignment == 0 || Alignment == 3 || Alignment == 6) // left
					{
						if (!enbackcolor)
						{
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(X_start, Y_start, Xe - X_start + 1, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,Xe - X_start + 1,m_PngData,
														X_start, Y_start, Xe - X_start + 1, H_Size);
								}
								else
									LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
					// else if(Alignment == 2)		LT268_dispaly_CutPicture(Xs,Y_start,Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
					else if (Alignment == 1 || Alignment == 4 || Alignment == 7) // center
					{
						if (!enbackcolor)
						{ // LT268_dispaly_CutPicture(Xs,Y_start, Xs, Y_start,Xs+(Xe-Xs+1-disp_w)-Xs, Y_start,FullScreen_addr,FullScreen_color);
							if(mix ==0)
							{
								if(ShowAddr == PIC_ON_LCDImg)
								{
									LT_getBackGround(X_start, Y_start, Xe - X_start + 1, H_Size, m_PngData,PIC_ON_LCDImg);
									LT268_buffer_to_TFT(0,0,Xe - X_start + 1,m_PngData,
														X_start, Y_start, Xe - X_start + 1, H_Size);
								}
								else
									LT268_dispaly_CutPicture(X_start, Y_start, X_start, Y_start, Xe - X_start + 1, H_Size, LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
							}
							else if(mix ==1)
								LT268_dispaly_CutPicture(X_start, Y_start, X_start - mixpic.x, Y_start - mixpic.y, Xe - X_start + 1, H_Size, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
						}
						else
							LT268_TFT_FillColor(X_start, Y_start, Xe - X_start + 1, H_Size, BackColor);
					}
				}
				// data_w = disp_w;  //Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
					i += 2;
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += temp_w;
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += temp_w;
				i += 2;
			}
		}
	}
	// printf("remaining part: Y_start %d , Xe %d  \r\n",Y_start,Ye);
	if (Y_start < Ye)
	{
		if (!enbackcolor)
		{
			if (mix == 0)
			{
				if(ShowAddr == PIC_ON_LCDImg)
				{
					LT_getBackGround(Xs, Y_start, box_w, Ye - Y_start + 1, m_PngData,PIC_ON_LCDImg);
					LT268_buffer_to_TFT(0,0,box_w,m_PngData,
										Xs, Y_start, box_w, Ye - Y_start + 1);
				}
				else
					LT268_dispaly_CutPicture(Xs, Y_start, 
						Xs, Y_start, box_w, Ye - Y_start + 1, 
						LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);

			}
			else if (mix == 1)
				LT268_dispaly_CutPicture(Xs, Y_start, Xs - mixpic.x, Y_start - mixpic.y, box_w, Ye - Y_start + 1, mixpic.w, mixpic.addr, mixpic.len, mixpic.flag);
		}
		else
			LT268_TFT_FillColor(Xs, Y_start, box_w, Ye - Y_start + 1, BackColor);
	}
}

/*******************************************************************************
 * Function Name : LT_Print_zk_Font_BUFF
 * Description   : Buffer a string.
 * Input         :
 * Output        : None
 * Return        : None
 ********************************************************************/
uint16_t LT_Print_zk_Font_BUFF(
	uint16_t encode // encoding type     0:GB2312  1:GBK  2:BIG5  3:UNICODE  4:ASCII
	,
	uint32_t FlashAddr // Font source address(exSpiFlash)
	,
	uint32_t ShowAddr // Displays the address of the layer
	,
	uint16_t width // Display the width of the layer
	,
	uint8_t W_Size // font width
	,
	uint8_t H_Size // font height
	,
	uint8_t Alignment // Alignment
	,
	uint32_t FontColor // The foreground color of the font
	,
	uint32_t BackColor // The background color of the font
	,
	uint8_t enbackcolor // Background color enable, 0:disable  1:enable
	//,uint16_t mix // mix mode, 0:with fullscreen interface   1:with specific pictures(Text box needs to be fully included)
	//,_PICINFO mixpic // mix picture info
	,
	uint16_t buf_w // width of buffer
	,
	uint16_t buf_h // height of buffer
	,
	uint8_t *buf // address of buffer
	,
	uint16_t buf_x // start x of buffer
	,
	uint16_t buf_y // start y of buffer
	,
	uint8_t dis_x // The interval between two adjacent fonts on the x-axis
	,
	uint8_t dis_y // The interval between two adjacent fonts on the y-axis
	,
	uint8_t *c // Address of text
	,
	uint16_t len_max // max lenght of text
)
{
	uint16_t temp = 0, temp_H = 0, temp_L = 0;
	uint32_t i = 0;
	uint8_t gray, gray_bit;
	uint16_t disp_w = 0, disp_i = 0;
	uint16_t temp_w, box_w = 0;
	uint8_t unicode_w;
	uint16_t font_byte; // bytes of a single font
	
	LT_ReadFlash_UI(Ascii_w, FlashAddr + 9, 95);
	LT_ReadFlash_UI(&gray, FlashAddr + 8, 1);

	if (gray == 0)
		gray_bit = 1;
	else if (gray == 1)
		gray_bit = 2;
	else if (gray == 2)
		gray_bit = 4;

	i = 0;
	if (encode == 4) // ASCII
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				box_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else
				break;
		}
	}
	else if (encode == 0) // GB2312
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				box_w += Ascii_w[c[i] - 0x20] + dis_x + 2;
				i++;
			}
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
			{
				box_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 1) // GBK
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				box_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
			{
				box_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 2) // BIG5
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				box_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
			{
				box_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 3) // UNICODE
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1)
		{
			unicode = (c[i] << 8) + c[i + 1];
			if (unicode < 128 && unicode > 0x00)
			{
				box_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
			}
			else if (unicode == 0x0000)
				break;
			else if (unicode >= start_code && unicode <= end_code)
			{
				box_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 6) // UNICODE
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];
		
		font_byte = (W_Size * gray_bit + 7) / 8 * H_Size;

		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1)
		{
			unicode = (c[i] << 8) + c[i + 1];
			if (unicode < 128 && unicode > 0x00)
			{
				box_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
			}
			else if (unicode == 0x0000)
				break;
			else if (unicode >= start_code && unicode <= end_code)
			{
				LT_ReadFlash_UI(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - start_code) * (font_byte + 1), 1);
				box_w += (unicode_w + dis_x);
				i += 2;
			}
			else
				break;
		}
	}

	if (Alignment == 0)
		buf_x = buf_x;
	else if (Alignment == 1)
		buf_x = buf_x - box_w / 2;
	else if (Alignment == 2)
		buf_x = buf_x - box_w + 1;
	// printf("cbuf_w,buf_h,box_w,box_h    %d    %d   %d   %d    \r\n \r\n",buf_w,buf_h,box_w,box_h);

	LT_ReadFlash_UI(Ascii_w, FlashAddr + 9, 95);
	LT_ReadFlash_UI(&gray, FlashAddr + 8, 1);

	i = 0;
	if (encode == 4) // ASCII
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = (Ascii_w[c[i] - 0x20] + dis_x + 2);
			// else if(c[i]==0x0A)                temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((buf_x + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (buf_y + H_Size > buf_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i; disp_i++)
				{
					LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
													FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
													buf_x, buf_y, buf_w, buf);

					buf_x += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				buf_y += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
		}
	}
	else if (encode == 0) // GB2312
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
				temp_w = W_Size + dis_x;
			// else if(c[i]==0x0A)                temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((buf_x + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (buf_y + H_Size > buf_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{
						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
														buf_x, buf_y, buf_w, buf);

						buf_x += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0xa1 && c[disp_i] != 0xFF)
					{
						LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, &c[disp_i],
														buf_x, buf_y, buf_w, buf);

						buf_x += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				buf_y += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 1) // GBK
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
				temp_w = W_Size + dis_x;
			//		  else if(c[i]==0x0A)                									temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((buf_x + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (buf_y + H_Size > buf_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{

						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
														buf_x, buf_y, buf_w, buf);

						buf_x += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0x81 && c[disp_i + 1] >= 0x40 && c[disp_i] != 0xFF)
					{

						LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, &c[disp_i],
														buf_x, buf_y, buf_w, buf);

						buf_x += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				buf_y += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 2) // BIG5
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
				temp_w = W_Size + dis_x;
			//		  else if(c[i]==0x0A)                									temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((buf_x + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (buf_y + H_Size > buf_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{

						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
														buf_x, buf_y, buf_w, buf);

						buf_x += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0xa1 && c[disp_i + 1] >= 0x40)
					{

						LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, &c[disp_i],
														buf_x, buf_y, buf_w, buf);

						buf_x += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				buf_y += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 3) // UNICODE
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode == 0x0000)
				len_max = i;
			else if (unicode >= start_code && unicode <= end_code)
				temp_w = W_Size + dis_x;
			//		  else if(c[i]==0x0A)                                   temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((buf_x + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (buf_y + H_Size > buf_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					unicode_temp = (c[disp_i] << 8) + c[disp_i + 1];
					if (unicode_temp < 128 && unicode_temp > 0x00)
					{

						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[unicode_temp - 0x20] + dis_x + 2, &c[disp_i + 1],
														buf_x, buf_y, buf_w, buf);

						buf_x += (Ascii_w[unicode_temp - 0x20] + dis_x + 2);
						disp_i += 2;
					}
					else if (unicode_temp >= start_code && unicode_temp <= end_code)
					{

						LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, (uint8_t *)(unicode_temp - start_code),
														buf_x, buf_y, buf_w, buf);

						buf_x += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i += 2;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				buf_y += H_Size;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
					i += 2;
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 6) // UNICODE
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode == 0x0000)
				len_max = i;
			else if (unicode >= start_code && unicode <= end_code)
			{
				LT_ReadFlash_UI(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - start_code) * (font_byte + 1), 1);
				temp_w = (unicode_w + dis_x);
			}
			//		  else if(c[i]==0x0A)                                   temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			// Displays a line of fonts, one by one from left to right
			if ((buf_x + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (buf_y + H_Size > buf_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					unicode_temp = (c[disp_i] << 8) + c[disp_i + 1];
					if (unicode_temp < 128 && unicode_temp > 0x00)
					{

						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[unicode_temp - 0x20] + dis_x + 2, &c[disp_i + 1],
														buf_x, buf_y, buf_w, buf);

						buf_x += (Ascii_w[unicode_temp - 0x20] + dis_x + 2);
						disp_i += 2;
					}
					else if (unicode_temp >= start_code && unicode_temp <= end_code)
					{

						LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, (uint8_t *)(unicode_temp - start_code),
														buf_x, buf_y, buf_w, buf);

						LT_ReadFlash_UI(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode_temp - start_code) * (font_byte + 1), 1);
						buf_x += (unicode_w + dis_x);
						disp_i += 2;
					}
					else
						disp_i += 2;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				buf_y += H_Size;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
					i += 2;
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += temp_w;
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += temp_w;
				i += 2;
			}
		}
	}

	return 0;
}

/***********************************************************************************
* Function Name : text_display
* Description   : Show text.
* Input         : - type: text info sources
				  - buff: text info
* Output        : None
* Return        : None
************************************************************************************/
uint8_t font_layflag = 0;
void text_display(uint8_t type, uint8_t *buff)
{
	uint16_t xs, ys, xe, ye; // Display box
	uint8_t Zk_id, w, h;	 // Font ID
	uint8_t encode;			 // encoding type
	uint8_t Alignment, transparent, star;
	uint32_t fcolor, bcolor; // The foreground color of the font, The background color of the font
	uint16_t p_add, p_len, pointer;
	uint32_t zk_addr;
	uint8_t buff1[4] = {0};
	uint8_t lay_flag;	
	
	if (type == 0) // instruction information source is configuration file
	{
		p_add = (buff[5] + (buff[6] << 8)) * 2;
		p_len = buff[7] + (buff[8] << 8);
		xs = buff[9] + (buff[10] << 8);
		ys = buff[11] + (buff[12] << 8);
		xe = buff[13] + (buff[14] << 8);
		ye = buff[15] + (buff[16] << 8);
		w = buff[17];
		h = buff[18];
		Zk_id = buff[19];
		encode = buff[20];
		Alignment = buff[21];
		bcolor = buff[22] + (buff[23] << 8) + (buff[24] << 16);
		fcolor = buff[25] + (buff[26] << 8) + (buff[27] << 16);
		transparent = buff[28] & 0x01;
		star = (buff[28] & 0x02) >> 1;
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		p_add = (var[pointer + 1] + (var[pointer + 2] << 8)) * 2;
		p_len = var[pointer + 3] + (var[pointer + 4] << 8);
		xs = var[pointer + 5] + (var[pointer + 6] << 8);
		ys = var[pointer + 7] + (var[pointer + 8] << 8);
		xe = var[pointer + 9] + (var[pointer + 10] << 8);
		ye = var[pointer + 11] + (var[pointer + 12] << 8);
		w = var[pointer + 13];
		h = var[pointer + 14];
		Zk_id = var[pointer + 15];
		encode = var[pointer + 16];
		Alignment = var[pointer + 17];
		bcolor = var[pointer + 18] + (var[pointer + 19] << 8) + (var[pointer + 20] << 16);
		fcolor = var[pointer + 21] + (var[pointer + 22] << 8) + (var[pointer + 23] << 16);
		transparent = var[pointer + 24] & 0x01 ;
		star = (var[pointer + 24] & 0x02) >> 1;	
	}

	if (Pop_up_flag == 1) // Popup offset
	{
		xs += Pop_up_x;
		ys += Pop_up_y;
		xe += Pop_up_x;
		ye += Pop_up_y;
	}

	LT_ReadFlash_UI(buff1, addr_index[2] + Zk_id * 8, 4);
	zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
	
//	lay_flag = 0;
//	font_layflag = lay_flag;
	LT_Print_zk_Font(encode, zk_addr,
					 font_layflag, LCD_XSIZE_TFT, w, h, Alignment, fcolor, bcolor, transparent, PIC_ON_BaseImg, PICINFO[0], star,
					 xs, ys, xe, ye,
					 0, 0, &var[p_add], p_len * 2);
}

/***********************************************************************************
* Function Name : data_display
* Description   : Show numbers in font.
* Input         : - type: data info sources
				  - buff: data info
* Output        : None
* Return        : None
************************************************************************************/
void data_display(uint8_t type, uint8_t *buff)
{

	uint8_t font_w, font_h,zk_id, Alignment;
	uint8_t N_int, D_int;
	uint8_t unit_len;
	uint8_t buff1[4] = {0};
	uint8_t data_type;
	uint16_t p_add, pointer;
	uint16_t x, y;
	uint32_t fcolor, zk_addr;
	uint8_t i, n = 0, k = 0, m = 0;
	int16_t dx, dy, dw, dh;
	
	int8_t value0 = 0;
	int16_t value1 = 0;
	int32_t value2 = 0;
	uint32_t value3 = 0;
	int64_t value = 0;
	uint16_t num = 0, nflag = 0, flag = 0;
	uint8_t temp_num;

	uint8_t leading_zero = 0;
	memset(Display_buff, 0, 100);

	if (type == 0)		// Instruction information source is configuration file
	{
		p_add = (buff[5] + (buff[6] << 8));
		Var_AddrRemapping(&p_add);
		p_add = p_add*2;
		x = buff[7] + (buff[8] << 8);
		y = buff[9] + (buff[10] << 8);
		fcolor = buff[11] + (buff[12] << 8) + (buff[13] << 16);
		zk_id = buff[14];
		font_w = buff[15];
		Alignment = buff[16] & 0x7F;
		leading_zero = (buff[16] & 0x80) >> 7;
		N_int = buff[17];
		D_int = buff[18];
		data_type = buff[19];
		unit_len = buff[20];
	}
	else if (type == 1)	// Instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		p_add = (var[pointer + 1] + (var[pointer + 2] << 8));
		Var_AddrRemapping(&p_add);
		p_add = p_add*2;
		x = var[pointer + 3] + (var[pointer + 4] << 8);
		y = var[pointer + 5] + (var[pointer + 6] << 8);
		fcolor = var[pointer + 7] + (var[pointer + 8] << 8) + (var[pointer + 9] << 16);
		zk_id = var[pointer + 10];
		font_w = var[pointer + 11];
		Alignment = var[pointer + 12] & 0x7F;
		leading_zero = (var[pointer + 12] & 0x80) >> 7;
		N_int = var[pointer + 13];
		D_int = var[pointer + 14];
		data_type = var[pointer + 15];
		unit_len = var[pointer + 16];
	}

	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
	}

	if (data_type == 0x00)
	{
		value3 = var[p_add + 1];
		value = value3;
	}
	else if (data_type == 0x01)
	{
		value3 = (var[p_add] << 8) + var[p_add + 1];
		value = value3;
	}
	else if (data_type == 0x02)
	{
		value3 = (0xFF000000 & (var[p_add] << 24)) | (var[p_add + 1] << 16) | (var[p_add + 2] << 8) | var[p_add + 3];
		value = value3;
	}
	else if (data_type == 0x80)
	{
		value0 = var[p_add + 1];
		value = value0;
	}
	else if (data_type == 0x81)
	{
		value1 = (var[p_add] << 8) + var[p_add + 1];
		value = value1;
	}
	else if (data_type == 0x82)
	{
		value2 = (var[p_add] << 24) | (var[p_add + 1] << 16) | (var[p_add + 2] << 8) | var[p_add + 3];
		value = value2;
	}
	else if (data_type == 0x83)
	{
		value = (0xFF000000 & (var[p_add] << 24)) + (var[p_add + 1] << 16) + (var[p_add + 2] << 8) + var[p_add + 3];
		value = ((value << 24) << 8) + (0xFF000000 & (var[p_add + 4] << 24)) + (var[p_add + 5] << 16) + (var[p_add + 6] << 8) + var[p_add + 7];
	}

	memset(Display_buff, 0, 50);

	if (value < 0)
	{
		Display_buff[num] = '-'; // negative number
		value = value * (-1);	// Become an integer
		nflag = 1;
		num++;
	}

	if (value < 1000000000000000000)
		value = value % ((int64_t)pow(10, N_int + D_int));
//	LTPrintf("value    %d    leading_zero %d  \r\n  ",value,leading_zero);


	for (i = 0; i < N_int; i++) // Integer part
	{
		temp_num = value / (int64_t)pow(10, N_int - i - 1 + D_int);

		if(leading_zero && temp_num == 0)
		{
			Display_buff[num] = '0';     // leading zero
			num++;
			flag = 1;
		}
		else
		{
//			LTPrintf("i+1,N_int,flag    %d   %d  %d  \r\n  ",i+1,N_int,flag);
			if(temp_num != 0 || flag == 1)
			{
				Display_buff[num] = temp_num + '0';
				num++;
				flag = 1;
			}
			else if((i+1 == N_int)&& flag == 0)
			{
				Display_buff[num] = '0';
				num++;
			}
		}
		value = value % (int64_t)pow(10, N_int - i - 1 + D_int);
	}
	if (D_int > 0)
	{
		if(N_int==0)
		{
			Display_buff[num] = '0'; //"0"
			num++;
		}
		Display_buff[num] = '.'; //"."
		num++;

		for (i = 0; i < D_int; i++) // Fractional part
		{
			temp_num = value / (int64_t)pow(10, D_int - i - 1);
			Display_buff[num] = temp_num + '0';
			num++;
			value = value % (int64_t)pow(10, D_int - i - 1);
		}
	}
	for (k = 0; k < unit_len; k++)
	{
		if (type == 0)
			Display_buff[num++] = buff[21 + k];
		else if (type == 1)
			Display_buff[num++] = var[pointer + 17 + k];
	}

	//�������
	dw = font_w * (N_int + D_int + 2);

	LT_ReadFlash_UI(buff1, addr_index[2] + zk_id * 8, 4);
	zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
	LT_ReadFlash_UI(&font_h, zk_addr + 3, 1);
	dh = font_h;

	dw = LT_Print_zk_Font(4, zk_addr,
					 LAY_BUFF1, LCD_XSIZE_TFT, font_w, font_h, Alignment, fcolor, Black, 0, 0, PICINFO[0], 2,
					 0, 0, 0 + dw - 1, 0 + dh - 1,
					 0, 0, Display_buff, sizeof(Display_buff));

	if (dw > data_D_w[data_D_num])
		;//dw = dw;
	else
		dw = data_D_w[data_D_num];

	data_D_w[data_D_num] = dw;


	if (Alignment == 0) // left
	{
		dx = x;
		dy = y;
		if(dx + dw > LCD_XSIZE_TFT) dw = LCD_XSIZE_TFT - dx;
	}
	else if (Alignment == 2) // right
	{
		dx = x - dw;
		dy = y;
		if(dx < 0) 
		{
			dx = 0;
			dw = x;
		}
	}
	else if (Alignment == 1) // center
	{
		dx = x - dw/2;
		dy = y;
		if(dx < 0) 
		{
			dx = 0;
		}
		if(dx + dw > LCD_XSIZE_TFT) dw = LCD_XSIZE_TFT - dx;

	}


	// debug
	// printf("dx    %d   %d   %d   %d      \r\n  ",dx,dy,dx+dw,dy+dh);
	
	LT_Print_zk_Font(4, zk_addr,
					 LAY_BUFF1, LCD_XSIZE_TFT, font_w, font_h, Alignment, fcolor, Black, 0, 0, PICINFO[0], 0,
					 dx, dy, dx + dw - 1, dy + dh - 1,
					 0, 0, Display_buff, sizeof(Display_buff));


}

/***********************************************************************************
* Function Name : pic_date_display
* Description   : Display data in picture mode.
* Input         : - type: data info sources
				  - buff: data info
* Output        : None
* Return        : None
************************************************************************************/
void pic_date_display(uint8_t type, uint8_t *buff)
{
	uint16_t p_add, p_len, pointer;
	uint16_t x, y, xd, w, x1;
	uint16_t simage, eimage;
	uint8_t data_type, I_num, D_num, Alig, i = 0, num = 0;
	uint8_t flag = 0, nflag = 0;
	uint16_t num_w, dot_w, neg_w, h, canvas_numw, canvas_dotw, canvas_negw;
	int8_t value0 = 0;
	int16_t value1 = 0;
	int32_t value2 = 0;
	uint32_t value3 = 0;
	int64_t value = 0;
	uint16_t tft_x, buf_x;
	uint8_t buff1[12] = {0};
	uint8_t leading_zero = 0;

	if (type == 0)		// Instruction information source is configuration file
	{
		p_add = (buff[5] + (buff[6] << 8)) * 2;
		data_type = buff[7];
		x = buff[8] + (buff[9] << 8);
		y = buff[10] + (buff[11] << 8);
		I_num = buff[12];
		D_num = buff[13];
		Alig = buff[14] & 0x7F;
		leading_zero = (buff[14] & 0x80) >> 7;
		simage = buff[15] + (buff[16] << 8);
		eimage = buff[17] + (buff[18] << 8);
	}
	else if (type == 1) // Instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		p_add = (var[pointer + 1] + (var[pointer + 2] << 8)) * 2;
		data_type = var[pointer + 3];
		x = var[pointer + 4] + (var[pointer + 5] << 8);
		y = var[pointer + 6] + (var[pointer + 7] << 8);
		I_num = var[pointer + 8];
		D_num = var[pointer + 9];
		Alig = var[pointer + 10] & 0x7F;
		leading_zero = (var[pointer + 10] & 0x80) >> 7;
		simage = var[pointer + 11] + (var[pointer + 12] << 8);
		eimage = var[pointer + 13] + (var[pointer + 14] << 8);
	}

	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
	}

	if (data_type == 0x00)
	{
		value3 = var[p_add + 1];
		value = value3;
	}
	else if (data_type == 0x01)
	{
		value3 = (var[p_add] << 8) + var[p_add + 1];
		value = value3;
	}
	else if (data_type == 0x02)
	{
		value3 = (0xFF000000 & (var[p_add] << 24)) | (var[p_add + 1] << 16) | (var[p_add + 2] << 8) | var[p_add + 3];
		value = value3;
	}
	else if (data_type == 0x80)
	{
		value0 = var[p_add + 1];
		value = value0;
	}
	else if (data_type == 0x81)
	{
		value1 = (var[p_add] << 8) + var[p_add + 1];
		value = value1;
	}
	else if (data_type == 0x82)
	{
		value2 = (var[p_add] << 24) | (var[p_add + 1] << 16) | (var[p_add + 2] << 8) | var[p_add + 3];
		value = value2;
	}
	else if (data_type == 0x83)
	{
		value = (0xFF000000 & (var[p_add] << 24)) + (var[p_add + 1] << 16) + (var[p_add + 2] << 8) + var[p_add + 3];
		value = ((value << 24) << 8) + (0xFF000000 & (var[p_add + 4] << 24)) + (var[p_add + 5] << 16) + (var[p_add + 6] << 8) + var[p_add + 7];
	}

	memset(Display_buff, 0, 50);

	if (value < 0)
	{
		Display_buff[num] = 11; // negative number
		value = value * (-1);	// Become an integer
		nflag = 1;
		num++;
	}

	if (value < 1000000000000000000)
		value = value % ((int64_t)pow(10, I_num + D_num));

	for (i = 0; i < I_num; i++) // Integer part 
	{
		Display_buff[num] = value / (int64_t)pow(10, I_num - i - 1 + D_num);
		if (leading_zero == 0)
		{
			if (Display_buff[num] != 0 || flag == 1)
			{
				num++;
				flag = 1; // The first digit is not 0
			}
		}
		else
		{
			num++;
			flag = 1; // The first digit is not 0
		}
		value = value % (int64_t)pow(10, I_num - i - 1 + D_num);
	}

	if (flag == 0)
	{
		Display_buff[num] = 0;
		num++;
	}
	if (D_num > 0)
	{
		Display_buff[num] = 10; //"."
		num++;
	}

	for (i = 0; i < D_num; i++) // Fractional part
	{
		Display_buff[num] = value / (int64_t)pow(10, D_num - i - 1);
		num++;
		value = value % (int64_t)pow(10, D_num - i - 1);
	}

	LT_ReadFlash_UI(buff1, addr_index[10] + 12 * simage + multi_language * 12 * addr_index[11], 12);
	pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
	num_w = buff1[4] + (buff1[5] << 8);
	h = buff1[6] + (buff1[7] << 8);
	pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
	pic_flag = buff1[11];

	PICINFO[0].w = num_w;
	PICINFO[0].h = h;
	PICINFO[0].len = pic_len;
	PICINFO[0].flag = pic_flag;
	PICINFO[0].addr = pic_add;

	if (D_num > 0) // have point
	{
		LT_ReadFlash_UI(buff1, addr_index[10] + 12 * (simage + 10) + multi_language * 12 * addr_index[11], 12); 
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		dot_w = buff1[4] + (buff1[5] << 8);

		PICINFO[1].w = dot_w;
		PICINFO[1].addr = pic_add;
	}

	if (nflag == 1) // have minus
	{
		LT_ReadFlash_UI(buff1, addr_index[10] + 12 * (simage + 11) + multi_language * 12 * addr_index[11], 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		neg_w = buff1[4] + (buff1[5] << 8);

		PICINFO[2].w = neg_w;
		PICINFO[2].addr = pic_add;
	}

	xd = 0;
	w = 0;
	i = 0;
	for (i = 0; i < num; i++) // display part
	{
		if (Display_buff[i] >= 0 && Display_buff[i] <= 9)
		{
			LT_ReadFlash_UI(buff1, addr_index[10] + 12 * (simage + Display_buff[i]) + multi_language * 12 * addr_index[11], 12);
			num_w = buff1[4] + (buff1[5] << 8);
			xd += num_w;
		}
		else if (Display_buff[i] == 10)
			xd += dot_w;
		else if (Display_buff[i] == 11)
			xd += neg_w;
	}
	
	if(xd%2) xd++;  //
	
	if (pdata_D_w[pdata_D_num] > xd) // The previous data is wider than the current data, and more content needs to be cleared
	{
		w = pdata_D_w[pdata_D_num];
		if (Alig == 0) // left
		{
			tft_x = x;
			buf_x = 0;
		}
		else if (Alig == 1) // center
		{
			tft_x = x - w / 2;
			buf_x = (w - xd) / 2;
		}
		else if (Alig == 2) // right
		{
			tft_x = x - w + 1;
			buf_x = w - xd;
		}
	}
	else
	{
		w = xd;
		buf_x = 0;
		if (Alig == 0)
			tft_x = x;
		else if (Alig == 1)
			tft_x = x - w / 2;
		else if (Alig == 2)
			tft_x = x - w + 1;
	}
	
	pdata_D_w[pdata_D_num] = xd; // Record width

//	LT268_pic_to_buffer(0, 0, w, m_PngData,
//						tft_x, y, LCD_XSIZE_TFT, FullScreen_addr,
//						w, h, FullScreen_flag);
	LT268_BG_to_buffer(0, 0, w, m_PngData,
					   tft_x, y,w, h);

	i = 0;
	for (i = 0; i < num; i++) // display
	{

		if (Display_buff[i] >= 0 && Display_buff[i] <= 9)
		{
			LT_ReadFlash_UI(buff1, addr_index[10] + 12 * (simage + Display_buff[i]) + multi_language * 12 * addr_index[11], 12);
			pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
			num_w = buff1[4] + (buff1[5] << 8);

			LT268_pic_to_buffer(buf_x, 0, w, m_PngData,
								0, 0, num_w, pic_add,
								num_w, h, pic_flag);
			buf_x += num_w;
		}
		else if (Display_buff[i] == 10)
		{
			LT268_pic_to_buffer(buf_x, 0, w, m_PngData,
								0, 0, PICINFO[1].w, PICINFO[1].addr,
								PICINFO[1].w, h, pic_flag);
			buf_x += dot_w;
		}
		else if (Display_buff[i] == 11)
		{
			LT268_pic_to_buffer(buf_x, 0, w, m_PngData,
								0, 0, PICINFO[2].w, PICINFO[2].addr,
								PICINFO[2].w, h, pic_flag);
			buf_x += neg_w;
		}
	}

	LT268_buffer_to_TFT(0, 0, w, m_PngData,
						tft_x, y, w, h);

	
}

/***********************************************************************************
* Function Name : gif_display
* Description   : Show picture of gif.
* Input         : - type: gif info sources
				  - buff: gif info
* Output        : None
* Return        : None
************************************************************************************/
void gif_display(uint8_t type, uint8_t *buff)
{
	uint8_t rbuff[16], i;
	uint16_t p_add, p_len, pointer;
	uint16_t x, y, w, h;
	uint16_t V_stop, V_start, gif_id, V_once;
	uint8_t reset_En, mode, t_d;
	uint32_t pic_addr;
	uint8_t on_gif = 0;

	if (type == 0) // instruction information source is configuration file
	{
		on_gif = (buff[4] & 0x80) >> 7;
		p_add = buff[5] + (buff[6] << 8);
		x = buff[7] + (buff[8] << 8);
		y = buff[9] + (buff[10] << 8);
		w = buff[11] + (buff[12] << 8);
		h = buff[13] + (buff[14] << 8);
		gif_id = buff[15] + (buff[16] << 8);
		reset_En = buff[17];
		t_d = buff[18];
		V_start = buff[19] + (buff[20] << 8);
		V_stop = buff[21] + (buff[22] << 8);
		mode = buff[23];
		V_once = buff[24] + (buff[25] << 8);
		for (i = 0; i < 32; i += 4)
		{
			gGif_Info[Gif_num].var_addr[i / 4] = buff[26 + i] + (buff[26 + i + 1] << 8);
			gGif_Info[Gif_num].var[i / 4] = buff[26 + i + 2] + (buff[26 + i + 3] << 8);
		}
		for(i=0;i<8;i++)
			Var_AddrRemapping(&gGif_Info[Gif_num].var_addr[i]);
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = buff[2] + (buff[3] << 8) * 2;
		on_gif = (var[pointer] & 0x80) >> 7;
		p_add = var[pointer + 1] + (var[pointer + 2] << 8);
		x = var[pointer + 3] + (var[pointer + 4] << 8);
		y = var[pointer + 5] + (var[pointer + 6] << 8);
		w = var[pointer + 7] + (var[pointer + 8] << 8);
		h = var[pointer + 9] + (var[pointer + 10] << 8);
		gif_id = var[pointer + 11] + (var[pointer + 12] << 8);
		reset_En = var[pointer + 13];
		t_d = var[pointer + 14];
		V_start = var[pointer + 15] + (var[pointer + 16] << 8);
		V_stop = var[pointer + 17] + (var[pointer + 18] << 8);
		mode = var[pointer + 19];
		V_once = var[pointer + 20] + (var[pointer + 21] << 8);
		for (i = 0; i < 32; i += 4)
		{
			gGif_Info[Gif_num].var_addr[i / 4] = var[pointer + 22 + i] + (var[pointer + 22 + i + 1] << 8);
			gGif_Info[Gif_num].var[i / 4] = var[pointer + 22 + i + 2] + (var[pointer + 22 + i + 3] << 8);
		}
		for(i=0;i<8;i++)
			Var_AddrRemapping(&gGif_Info[Gif_num].var_addr[i]);
	}

	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
	}

	gGif_Info[Gif_num].p_add = p_add;
	gGif_Info[Gif_num].x = x;
	gGif_Info[Gif_num].y = y;
	gGif_Info[Gif_num].w = w;
	gGif_Info[Gif_num].h = h;
	gGif_Info[Gif_num].gif_id = gif_id;
	gGif_Info[Gif_num].reset_En = reset_En;
	gGif_Info[Gif_num].t_d = t_d;
	gGif_Info[Gif_num].V_stop = V_stop;
	gGif_Info[Gif_num].V_start = V_start;
	gGif_Info[Gif_num].V_once = V_once;
	gGif_Info[Gif_num].mode = mode;
	gGif_Info[Gif_num].p_c = 0;
	gGif_Info[Gif_num].flag = 1;
	LT_ReadFlash_UI(rbuff, addr_index[8] + gif_id * 8, 8);
	gGif_Info[Gif_num].addr = rbuff[0] + (rbuff[1] << 8) + (rbuff[2] << 16) + (rbuff[3] << 24);
	gGif_Info[Gif_num].total = rbuff[4] + (rbuff[5] << 8) + (rbuff[6] << 16);


	if(on_gif == 1)
		gGif_Info[Gif_num].on_gif = 1;
	else gGif_Info[Gif_num].on_gif = 0;
	/*Display the first frame when stopping*/
	if (((var[gGif_Info[Gif_num].p_add * 2] << 8) + var[gGif_Info[Gif_num].p_add * 2 + 1]) == gGif_Info[Gif_num].V_stop)
	{
		LT_ReadFlash_UI(rbuff, gGif_Info[Gif_num].addr, 16);
		pic_addr = rbuff[0] + (rbuff[1] << 8) + (rbuff[2] << 16) + (rbuff[3] << 24);
		pic_flag = rbuff[15];

		if(gGif_Info[Gif_num].on_gif)
		{
			LT_BG_GIFID = gGif_Info[Gif_num].gif_id;
			LT_getBackGround(gGif_Info[Gif_num].x, gGif_Info[Gif_num].y, gGif_Info[Gif_num].w, gGif_Info[Gif_num].h, m_PngData,PIC_ON_LCDImg);
			LT268_pic_to_buffer(0,0,gGif_Info[Gif_num].w,m_PngData,
								0,0,gGif_Info[Gif_num].w,pic_addr,
								gGif_Info[Gif_num].w, gGif_Info[Gif_num].h,pic_flag);
			LT268_buffer_to_TFT(0,0,gGif_Info[Gif_num].w,m_PngData,
								gGif_Info[Gif_num].x,gGif_Info[Gif_num].y,gGif_Info[Gif_num].w, gGif_Info[Gif_num].h);
		}
		else if ((pic_flag >= 0 && pic_flag < 5) || pic_flag == ColorARGB8565)
			LT_ShowPicture(gGif_Info[Gif_num].x, gGif_Info[Gif_num].y, gGif_Info[Gif_num].w, gGif_Info[Gif_num].h, pic_addr, pic_len, pic_flag);

	}

	LT_ShowGifPicture(Gif_num);
	Gif_num++;
}

uint8_t LT_ShowGifPicture(uint8_t num)
{
	uint8_t rbuff[16], i;
	uint32_t pic_addr;

	if (((var[gGif_Info[num].p_add * 2] << 8) + var[gGif_Info[num].p_add * 2 + 1]) == gGif_Info[num].V_start)
	{
		gGif_Info[num].flag = 1;
		if (gGif_Info[num].p_c >= gGif_Info[num].total)
			gGif_Info[num].p_c = 0;

		LT_ReadFlash_UI(rbuff, gGif_Info[num].addr + gGif_Info[num].p_c * 16, 16);

		pic_addr = rbuff[0] + (rbuff[1] << 8) + (rbuff[2] << 16) + (rbuff[3] << 24);
		pic_flag = rbuff[15];
		
//		printf("LT_ShowGifPicture   x%x  pic_flag x%x \r\n ", pic_addr , pic_flag);
		
		// In the keyboard input interface
		if (DioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gDio_Info[Dio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gDio_Info[Dio_num].Xs || gGif_Info[num].y > gDio_Info[Dio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gDio_Info[Dio_num].Ys))
			{
				return 0;
			}
		}
		else if (AioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gAio_Info[Aio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gAio_Info[Aio_num].Xs || gGif_Info[num].y > gAio_Info[Aio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gAio_Info[Aio_num].Ys))
			{
				return 0;
			}
		}
		else if (GBKioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gGBKio_Info[GBKio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gGBKio_Info[GBKio_num].Xs || gGif_Info[num].y > gGBKio_Info[GBKio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gGBKio_Info[GBKio_num].Ys))
			{
				return 0;
			}
		}

		if(gGif_Info[num].on_gif)
		{
			LT_BG_GIFID = gGif_Info[num].gif_id;
			LT_getBackGround(gGif_Info[num].x, gGif_Info[num].y, gGif_Info[num].w, gGif_Info[num].h, m_PngData,PIC_ON_LCDImg);
			LT268_pic_to_buffer(0,0,gGif_Info[num].w,m_PngData,
								0,0,gGif_Info[num].w,pic_addr,
								gGif_Info[num].w, gGif_Info[num].h,pic_flag);
			LT268_buffer_to_TFT(0,0,gGif_Info[num].w,m_PngData,
								gGif_Info[num].x,gGif_Info[num].y,gGif_Info[num].w, gGif_Info[num].h);
		}
		else if ((pic_flag >= 0 && pic_flag < 5) || pic_flag == ColorARGB8565)
			LT_ShowPicture(gGif_Info[num].x, gGif_Info[num].y, gGif_Info[num].w, gGif_Info[num].h, pic_addr, pic_len, pic_flag);
		
		
		gGif_Info[num].p_c++;
	}
	else if (((var[gGif_Info[num].p_add * 2] << 8) + var[gGif_Info[num].p_add * 2 + 1]) == gGif_Info[num].V_once)
	{
		gGif_Info[num].flag = 1;
		if (gGif_Info[num].p_c >= gGif_Info[num].total)
		{
			gGif_Info[num].p_c = 0;
			var[gGif_Info[num].p_add * 2] = (gGif_Info[num].V_stop >> 8) & 0xFF;
			var[gGif_Info[num].p_add * 2 + 1] = (gGif_Info[num].V_stop) & 0xFF;
			for (i = 0; i < 8; i++)
			{
				if (gGif_Info[num].var_addr[i] != 0xFFFF && gGif_Info[num].var_addr[i] <= VAR_ADDR_E)
				{
					var[gGif_Info[num].var_addr[i] * 2] = (gGif_Info[num].var[i] >> 8) & 0xFF;
					var[gGif_Info[num].var_addr[i] * 2 + 1] = gGif_Info[num].var[i] & 0xFF;

					if (gGif_Info[num].var_addr[i] >= VAR_ADDR_S)
					{
						uint16_t ppage = pic_id;
						reg_operation(gGif_Info[num].var_addr[i]);
						if(ppage!=pic_id) return 0;
					}
				}
			}

			return 0;
		}

		LT_ReadFlash_UI(rbuff, gGif_Info[num].addr + gGif_Info[num].p_c * 16, 16);
		pic_addr = rbuff[0] + (rbuff[1] << 8) + (rbuff[2] << 16) + (rbuff[3] << 24);
		pic_flag = rbuff[15];

		// In the keyboard input interface
		if (DioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gDio_Info[Dio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gDio_Info[Dio_num].Xs || gGif_Info[num].y > gDio_Info[Dio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gDio_Info[Dio_num].Ys))
			{
				return 0;
			}
		}
		else if (AioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gAio_Info[Aio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gAio_Info[Aio_num].Xs || gGif_Info[num].y > gAio_Info[Aio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gAio_Info[Aio_num].Ys))
			{
				return 0;
			}
		}
		else if (GBKioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gGBKio_Info[GBKio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gGBKio_Info[GBKio_num].Xs || gGif_Info[num].y > gGBKio_Info[GBKio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gGBKio_Info[GBKio_num].Ys))
			{
				return 0;
			}
		}

		if(gGif_Info[num].on_gif)
		{
			LT_BG_GIFID = gGif_Info[num].gif_id;
			LT_getBackGround(gGif_Info[num].x, gGif_Info[num].y, gGif_Info[num].w, gGif_Info[num].h, m_PngData,PIC_ON_LCDImg);
			LT268_pic_to_buffer(0,0,gGif_Info[num].w,m_PngData,
								0,0,gGif_Info[num].w,pic_addr,
								gGif_Info[num].w, gGif_Info[num].h,pic_flag);			
			LT268_buffer_to_TFT(0,0,gGif_Info[num].w,m_PngData,
								gGif_Info[num].x,gGif_Info[num].y,gGif_Info[num].w, gGif_Info[num].h);
		}
		else if ((pic_flag >= 0 && pic_flag < 5) || pic_flag == ColorARGB8565)
			LT_ShowPicture(gGif_Info[num].x, gGif_Info[num].y, gGif_Info[num].w, gGif_Info[num].h, pic_addr, pic_len, pic_flag);
		
		gGif_Info[num].p_c++;
	}
	else if (((var[gGif_Info[num].p_add * 2] << 8) + var[gGif_Info[num].p_add * 2 + 1]) == gGif_Info[num].V_stop)
	{
		// In the keyboard input interface
		if (DioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gDio_Info[Dio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gDio_Info[Dio_num].Xs || gGif_Info[num].y > gDio_Info[Dio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gDio_Info[Dio_num].Ys))
			{
				return 0;
			}
		}
		else if (AioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gAio_Info[Aio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gAio_Info[Aio_num].Xs || gGif_Info[num].y > gAio_Info[Aio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gAio_Info[Aio_num].Ys))
			{
				return 0;
			}
		}
		else if (GBKioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gGBKio_Info[GBKio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gGBKio_Info[GBKio_num].Xs || gGif_Info[num].y > gGBKio_Info[GBKio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gGBKio_Info[GBKio_num].Ys))
			{
				return 0;
			}
		}

		gGif_Info[num].flag = 1;
		if (gGif_Info[num].reset_En == 1) // gif reset
		{
			gGif_Info[num].p_c = 0;
		}
	}
	else if (((var[gGif_Info[num].p_add * 2] << 8) + var[gGif_Info[num].p_add * 2 + 1]) == 0xFFFF)
	{
		// In the keyboard input interface
		if (DioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gDio_Info[Dio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gDio_Info[Dio_num].Xs || gGif_Info[num].y > gDio_Info[Dio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gDio_Info[Dio_num].Ys))
			{
				return 0;
			}
		}
		else if (AioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gAio_Info[Aio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gAio_Info[Aio_num].Xs || gGif_Info[num].y > gAio_Info[Aio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gAio_Info[Aio_num].Ys))
			{
				return 0;
			}
		}
		else if (GBKioKb_flag == 1)
		{
			if (!(gGif_Info[num].x > gGBKio_Info[GBKio_num].Xe || (gGif_Info[num].x + gGif_Info[num].w) < gGBKio_Info[GBKio_num].Xs || gGif_Info[num].y > gGBKio_Info[GBKio_num].Ye || (gGif_Info[num].y + gGif_Info[num].h) < gGBKio_Info[GBKio_num].Ys))
			{
				return 0;
			}
		}
		if (gGif_Info[num].flag != 0)
		{

//			LT268_dispaly_CutPicture(gGif_Info[num].x, gGif_Info[num].y,
//									 gGif_Info[num].x, gGif_Info[num].y, gGif_Info[num].w, gGif_Info[num].h,
//										LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
		if(gGif_Info[num].on_gif)
		{
			LT_BG_GIFID = gGif_Info[num].gif_id;
			LT_getBackGround(gGif_Info[num].x, gGif_Info[num].y, gGif_Info[num].w, gGif_Info[num].h, m_PngData,PIC_ON_LCDImg);
			LT268_buffer_to_TFT(0,0,gGif_Info[num].w,m_PngData,
								gGif_Info[num].x,gGif_Info[num].y,gGif_Info[num].w, gGif_Info[num].h);
		}
		else
			LT268_dispaly_CutPicture(gGif_Info[num].x, gGif_Info[num].y,
									 gGif_Info[num].x, gGif_Info[num].y, gGif_Info[num].w, gGif_Info[num].h,
										LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
		
			gGif_Info[num].flag = 0;
		}
		gGif_Info[num].p_c = 0;
	}
}

void show_gif(void)
{
	if (Gif_num > 0 && Gif_flag == 1)
	{
		Gif_flag = 0;

		for (uint8_t i = 0; i < Gif_num; i++)
			gGif_Info[i].t_c++;
		for (uint8_t i = 0; i < Gif_num; i++)
		{
			if (gGif_Info[i].t_c >= gGif_Info[i].t_d) // display picture of gif
			{
				LT_ShowGifPicture(i);
				gGif_Info[i].t_c = 0;
			}
		}
	}
}

/***********************************************************************************
* Function Name : qr_code
* Description   : Show QRcode.
* Input         : - type: QRcode info sources
				  - buff: QRcode info
* Output        : None
* Return        : None
************************************************************************************/
void qr_code(uint8_t type, uint8_t *buff)
{
	uint16_t p_add, pointer, length;
	uint16_t i = 0, j = 0;
	uint16_t x1 = 0, y1 = 0, x, y;
	int32_t size = 49;
	uint8_t dxy = 0;
	uint8_t unit_pixle;
	uint16_t backgroud_size = 50; // White background magnification base

	if (type == 0) // instruction information source is configuration file
	{
		p_add = (buff[5] + (buff[6] << 8)) * 2;
		length = buff[7] + (buff[8] << 8);
		x = buff[9] + (buff[10] << 8);
		y = buff[11] + (buff[12] << 8);
		unit_pixle = buff[13];
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		p_add = (var[pointer + 1] + (var[pointer + 2] << 8)) * 2;
		length = var[pointer + 3] + (var[pointer + 4] << 8);
		x = var[pointer + 5] + (var[pointer + 6] << 8);
		y = var[pointer + 7] + (var[pointer + 8] << 8);
		unit_pixle = var[pointer + 9];
	}
	
	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
	}
	
	EncodeData(&var[p_add]);

	// m_nSymbleSize: It's the real QR code size
	size = size * unit_pixle / m_nSymbleSize;						// Size of a single black pixel of the actual QR code
	dxy = (backgroud_size * unit_pixle - m_nSymbleSize * size) / 2; // The actual QR code is at the beginning of the white background
	y1 = y + dxy;

	LT268_TFT_FillColor(x, y, backgroud_size * unit_pixle, backgroud_size * unit_pixle, White); // Enlarged white background size

	// display
	for (i = 0; i < m_nSymbleSize; i++)
	{
		x1 = dxy + x;
		for (j = 0; j < m_nSymbleSize; j++)
		{
			if (m_byModuleData[i][j])
			{
				LT268_TFT_FillColor(x1, y1, size, size, Black);
			}
			x1 += size;
		}
		y1 += size;
	}
}

#define RTC_BLANK 20
uint8_t RTC_num = 0;
uint8_t RTC_flag = 0;
RTC_Info gRTC_Info[RTC_SIZE];
/***********************************************************************************
* Function Name : Display_RTC
* Description   : Show digital clock.
* Input         : - gRTC: digital clock info sources
				  - status: digital clock status
* Output        : None
* Return        : None
************************************************************************************/
uint8_t Display_RTC(RTC_Info *gRTC, uint8_t status)
{
	uint8_t buff[12] = {0};
	uint8_t flag = 0;
	uint8_t mode = gRTC->mode;
	int8_t num = 0;
	uint16_t i = 0, ID[11];
	uint16_t x_date = 0, x_time = 0, width = 0, high = 0;
	uint16_t id_start = gRTC->ID_start;
	uint16_t x = gRTC->x;
	uint16_t y = gRTC->y;
	uint16_t x_src, y_src, x_des, y_des, w_real, h_real, cnt;

	uint8_t state = 0;	//0: Aligned 1: Unaligned

	if (mode == 0 || mode == 8) // Year/month/day/hour/minute/second
	{
		/* Display date*/
		num = 0;
		if (calendar.w_year / 1000)
			num = 0; // The number of digits is different
		else
		{
			num--;
			if ((calendar.w_year / 100 % 10) == 0)
			{
				num--;
				if ((calendar.w_year / 10 % 10) == 0)
					num--;
			}
		}

		if (num >= 0)
			ID[num] = (calendar.w_year) / 1000;
		if (num + 1 >= 0)
			ID[num + 1] = (calendar.w_year) / 100 % 10;
		if (num + 2 >= 0)
			ID[num + 2] = (calendar.w_year) / 10 % 10;
		if (num + 3 >= 0)
			ID[num + 3] = (calendar.w_year) % 10;
		ID[num + 4] = 11;
		if (state == 0)
		{
			ID[num + 5] = (calendar.w_month) / 10 % 10;
		}
		else 
		{
			if (((calendar.w_month) / 10 % 10) == 0)
				num--;
			else
				ID[num + 5] = (calendar.w_month) / 10 % 10;
		}
		ID[num + 6] = (calendar.w_month) % 10;
		ID[num + 7] = 12;

		if (state == 0)
		{
			ID[num + 8] = (calendar.w_date) / 10 % 10;
		}
		else
		{
			if (((calendar.w_date) / 10 % 10) == 0)
				num--;
			else
				ID[num + 8] = (calendar.w_date) / 10 % 10;
		}

		ID[num + 9] = (calendar.w_date) % 10;
		if (mode == 0)
			cnt = num + 9;
		else
		{
			ID[num + 10] = 13;
			cnt = num + 10;
		}
		
		for (i = 0; i <= cnt; i++)
		{
			if (id_start + ID[i] >= addr_index[11])
				continue; // ICON is available
			LT_ReadFlash_UI(buff, addr_index[10] + 12 * (id_start + ID[i]) + multi_language * 12 * addr_index[11], 12);
			pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
			pic_w = buff[4] + (buff[5] << 8);
			pic_h = buff[6] + (buff[7] << 8);
			pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
			pic_flag = buff[11];

			// Record the height and flag of the first valid ICON, and the following ICON arrangement shall be subject to this
			if (i == 0)
			{
				high = pic_h;
				flag = pic_flag;
			}

			if (pic_len != 0 && pic_flag != 0xFF) // ICON is not empty
			{
				x_date += pic_w;
			}
		}
		
		/*In the keyboard input interface*/
		if (DioKb_flag == 1)
		{
			if (!(x > gDio_Info[Dio_num].Xe || (x + x_date) < gDio_Info[Dio_num].Xs || y > gDio_Info[Dio_num].Ye || (y + high) < gDio_Info[Dio_num].Ys))
			{
				return 0;
			}
		}
		else if (AioKb_flag == 1)
		{
			if (!(x > gAio_Info[Aio_num].Xe || (x + x_date) < gAio_Info[Aio_num].Xs || y > gAio_Info[Aio_num].Ye || (y + high) < gAio_Info[Aio_num].Ys))
			{
				return 0;
			}
		}
		else if (GBKioKb_flag == 1)
		{
			if (!(x > gGBKio_Info[GBKio_num].Xe || (x + x_date) < gGBKio_Info[GBKio_num].Xs || y > gGBKio_Info[GBKio_num].Ye || (y + high) < gGBKio_Info[GBKio_num].Ys))
			{
				return 0;
			}
		}
		
		x_date = 0;

		for (i = 0; i <= cnt; i++)
		{
			if (id_start + ID[i] >= addr_index[11])
				continue; // ICON is available
			LT_ReadFlash_UI(buff, addr_index[10] + 12 * (id_start + ID[i]) + multi_language * 12 * addr_index[11], 12);
			pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
			pic_w = buff[4] + (buff[5] << 8);
			pic_h = buff[6] + (buff[7] << 8);
			pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
			pic_flag = buff[11];

			// Record the height and flag of the first valid ICON, and the following ICON arrangement shall be subject to this
			if (i == 0)
			{
				high = pic_h;
				flag = pic_flag;
			}

			if (pic_len != 0 && pic_flag != 0xFF) // ICON is not empty
			{
				if (flag == 0 || flag == 1 || flag == 2)
					LT_ShowPicture(x + x_date, y, pic_w, high, pic_add, pic_len, flag); 

				x_date += pic_w;
			}
		}

		if (status) // In order to remove the residual content in the tail
		{
			LT268_dispaly_CutPicture(x + x_date, y,
									 x + x_date, y, RTC_BLANK, high,
									 LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
		}

		/* Display time*/
		num = 0;
		if(state == 0)
		{
			ID[num] = (calendar.hour) / 10 % 10;
		}
		else
		{
			if ((calendar.hour / 10 % 10) == 0)
				num--; // The number of digits is different
			else
				ID[num] = (calendar.hour) / 10 % 10;
		}
		ID[num + 1] = (calendar.hour) % 10;
		ID[num + 2] = 10;
		ID[num + 3] = (calendar.min) / 10 % 10;
		ID[num + 4] = (calendar.min) % 10;
		ID[num + 5] = 10;
		ID[num + 6] = (calendar.sec) / 10 % 10;
		ID[num + 7] = (calendar.sec) % 10;
		cnt = num + 7;

		x = x + x_date + RTC_BLANK; // Pixel interval between time and date

		// display
		for (i = 0; i <= cnt; i++)
		{
			if (id_start + ID[i] >= addr_index[11])
				continue; // ICON is available
			LT_ReadFlash_UI(buff, addr_index[10] + 12 * (id_start + ID[i]) + multi_language * 12 * addr_index[11], 12);

			pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
			pic_w = buff[4] + (buff[5] << 8);
			pic_h = buff[6] + (buff[7] << 8);
			pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
			pic_flag = buff[11];
			
			if (i == 0) // Record the height and flag of the first valid ICON, and the following ICON arrangement shall be subject to this
			{
				high = pic_h;
				flag = pic_flag;
			}
			
			if (pic_len != 0 && pic_flag != 0xFF) // ICON is not empty
			{
				if (flag == 0 || flag == 1 || flag == 2)
					LT_ShowPicture(x + x_time, y, pic_w, high, pic_add, pic_len, flag); 
				x_time += pic_w;
			}
		}

		if (gRTC->Len_last > (x_date + RTC_BLANK + x_time) && status) // In order to remove the residual content in the tail
		{
			LT268_dispaly_CutPicture(x + x_time, y,
									 x + x_time, y, gRTC->Len_last - (x_date + RTC_BLANK + x_time), high,
									 LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
		}
		gRTC->Len_last = x_date + RTC_BLANK + x_time; // Record width
	}
	else if ((mode >= 1 && mode <= 6) || (mode >= 9 && mode <= 11))
	{
		if (mode == 1 || mode == 9)
		{
			num = 0;
			
			if (num >= 0)
				ID[num] = (calendar.w_year) / 1000;
			if (num + 1 >= 0)
				ID[num + 1] = (calendar.w_year) / 100 % 10;
			if (num + 2 >= 0)
				ID[num + 2] = (calendar.w_year) / 10 % 10;
			if (num + 3 >= 0)
				ID[num + 3] = (calendar.w_year) % 10;

			ID[num + 4] = 11;

			if(state == 0)
			{
				ID[num + 5] = calendar.w_month / 10 % 10;
			}
			else
			{
				if ((calendar.w_month / 10 % 10) == 0)
					num--;
				else
					ID[num + 5] = calendar.w_month / 10 % 10;
			}

			ID[num + 6] = (calendar.w_month) % 10;
			ID[num + 7] = 12;

			if(state == 0)
			{
				ID[num + 8] = calendar.w_date / 10 % 10;
			}
			else
			{
				if ((calendar.w_date / 10 % 10) == 0)
					num--;
				else
					ID[num + 8] = calendar.w_date / 10 % 10;
			}

			ID[num + 9] = calendar.w_date % 10;

			if (mode == 1)
				cnt = num + 9;
			else
			{
				ID[num + 10] = 13;
				cnt = num + 10;
			}
		}
		else if (mode == 2 || mode == 10)
		{
			num = 0;
			if (num >= 0)
				ID[num] = calendar.w_year / 1000;
			if (num + 1 >= 0)
				ID[num + 1] = calendar.w_year / 100 % 10;
			if (num + 2 >= 0)
				ID[num + 2] = calendar.w_year / 10 % 10;
			if (num + 3 >= 0)
				ID[num + 3] = calendar.w_year % 10;

			ID[num + 4] = 11;

			if(state == 0)
			{
				ID[num + 5] = calendar.w_month / 10 % 10;
			}
			else
			{
				if ((calendar.w_month / 10 % 10) == 0)
					num--;
				else
					ID[num + 5] = calendar.w_month / 10 % 10;
			}

			ID[num + 6] = calendar.w_month % 10;

			if (mode == 2)
				cnt = num + 6;
			else
			{
				ID[num + 7] = 12;
				cnt = num + 7;
			}
		}
		else if (mode == 3 || mode == 11)
		{
			num = 0;
			if (state == 0)
			{
				ID[num] = calendar.w_month / 10 % 10;
			}
			else
			{
				if ((calendar.w_month / 10 % 10) == 0)
					num--;
				else
					ID[num] = calendar.w_month / 10 % 10;
			}

			ID[num + 1] = calendar.w_month % 10;
			ID[num + 2] = 12;
	
			if (state == 0)
			{
				ID[num + 3] = calendar.w_date / 10 % 10;
			}
			else 
			{
				if ((calendar.w_date / 10 % 10) == 0)
					num--;
				else
					ID[num + 3] = calendar.w_date / 10 % 10;
			}

			ID[num + 4] = calendar.w_date % 10;

			if (mode == 3)
				cnt = num + 4;
			else
			{
				ID[num + 5] = 13;
				cnt = num + 5;
			}
		}
		else if (mode == 4)
		{
			num = 0;
			if (state == 0)
			{
				ID[num] = calendar.hour / 10 % 10;
			}
			else
			{
				if ((calendar.hour / 10 % 10) == 0)
					num--;
				else
					ID[num] = calendar.hour / 10 % 10;
			}
			ID[num + 1] = calendar.hour % 10;
			ID[num + 2] = 10;
			ID[num + 3] = calendar.min / 10 % 10;
			ID[num + 4] = calendar.min % 10;
			ID[num + 5] = 10;
			ID[num + 6] = calendar.sec / 10 % 10;
			ID[num + 7] = calendar.sec % 10;
			cnt = num + 7;
		}
		else if (mode == 5)
		{
			num = 0;
			if (state == 0)
			{
				ID[num] = calendar.hour / 10 % 10;
			}
			else
			{
				if ((calendar.hour / 10 % 10) == 0)
					num--;
				else
					ID[num] = calendar.hour / 10 % 10;
			}
			ID[num + 1] = calendar.hour % 10;
			ID[num + 2] = 10;
			ID[num + 3] = calendar.min / 10 % 10;
			ID[num + 4] = calendar.min % 10;
			cnt = num + 4;
		}
		else if (mode == 6)
		{
			num = 0;
			ID[num] = calendar.min / 10 % 10;
			ID[num + 1] = calendar.min % 10;
			ID[num + 2] = 10;
			ID[num + 3] = calendar.sec / 10 % 10;
			ID[num + 4] = calendar.sec % 10;
			cnt = num + 4;
		}

		
		for (i = 0; i <= cnt; i++)
		{
			if (id_start + ID[i] >= addr_index[11])
				continue;

			LT_ReadFlash_UI(buff, addr_index[10] + 12 * (id_start + ID[i]) + multi_language * 12 * addr_index[11], 12);
			pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
			pic_w = buff[4] + (buff[5] << 8);
			pic_h = buff[6] + (buff[7] << 8);
			pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
			pic_flag = buff[11];
			
			if (i == 0)
			{
				high = pic_h;
				flag = pic_flag;
			}
			if (pic_len != 0 && pic_flag != 0xFF)
			{
				x_time += pic_w;
			}
		}
		
		if (DioKb_flag == 1)
		{
			if (!(x > gDio_Info[Dio_num].Xe || (x + x_time) < gDio_Info[Dio_num].Xs || y > gDio_Info[Dio_num].Ye || (y + high) < gDio_Info[Dio_num].Ys))
			{
				return 0;
			}
		}
		else if (AioKb_flag == 1)
		{
			if (!(x > gAio_Info[Aio_num].Xe || (x + x_time) < gAio_Info[Aio_num].Xs || y > gAio_Info[Aio_num].Ye || (y + high) < gAio_Info[Aio_num].Ys))
			{
				return 0;
			}
		}
		else if (GBKioKb_flag == 1)
		{
			if (!(x > gGBKio_Info[GBKio_num].Xe || (x + x_time) < gGBKio_Info[GBKio_num].Xs || y > gGBKio_Info[GBKio_num].Ye || (y + high) < gGBKio_Info[GBKio_num].Ys))
			{
				return 0;
			}
		}
		
		x_time = 0;

		for (i = 0; i <= cnt; i++)
		{
			if (id_start + ID[i] >= addr_index[11])
				continue;

			LT_ReadFlash_UI(buff, addr_index[10] + 12 * (id_start + ID[i]) + multi_language * 12 * addr_index[11], 12);
			pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
			pic_w = buff[4] + (buff[5] << 8);
			pic_h = buff[6] + (buff[7] << 8);
			pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
			pic_flag = buff[11];

			if (i == 0)
			{
				high = pic_h;
				flag = pic_flag;
			}

			if (pic_len != 0 && pic_flag != 0xFF)
			{
				if (flag == 0 || flag == 1 || flag == 2)
					LT_ShowPicture(x + x_time, y, pic_w, pic_h, pic_add, pic_len, flag); 
				x_time += pic_w;
			}
		}

		if (gRTC->Len_last > x_time && status)
		{
			LT268_dispaly_CutPicture(x + x_time, y,
									 x + x_time, y, gRTC->Len_last - x_time, high,
									 LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
		}
		gRTC->Len_last = x_time;
	}
	else if (mode == 7) // week
	{
		ID[0] = 14 + calendar.week;

		if (id_start + ID[0] < addr_index[11])
		{
			LT_ReadFlash_UI(buff, addr_index[10] + 12 * (id_start + ID[0]) + multi_language * 12 * addr_index[11], 12);

			pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
			pic_w = buff[4] + (buff[5] << 8);
			pic_h = buff[6] + (buff[7] << 8);
			pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
			pic_flag = buff[11];

			if (DioKb_flag == 1)
			{
				if (!(x > gDio_Info[Dio_num].Xe || (x + pic_w) < gDio_Info[Dio_num].Xs || y > gDio_Info[Dio_num].Ye || (y + pic_h) < gDio_Info[Dio_num].Ys))
				{
					return 0;
				}
			}
			else if (AioKb_flag == 1)
			{
				if (!(x > gAio_Info[Aio_num].Xe || (x + pic_w) < gAio_Info[Aio_num].Xs || y > gAio_Info[Aio_num].Ye || (y + pic_h) < gAio_Info[Aio_num].Ys))
				{
					return 0;
				}
			}
			else if (GBKioKb_flag == 1)
			{
				if (!(x > gGBKio_Info[GBKio_num].Xe || (x + pic_w) < gGBKio_Info[GBKio_num].Xs || y > gGBKio_Info[GBKio_num].Ye || (y + pic_h) < gGBKio_Info[GBKio_num].Ys))
				{
					return 0;
				}
			}

			if (pic_len != 0 && pic_flag != 0xFF)
			{
				if (pic_flag == 0 || pic_flag == 1 || pic_flag == 2)
					LT_ShowPicture(x, y, pic_w, pic_h, pic_add, pic_len, pic_flag); 
			}
		}
	}
}

/***********************************************************************************
* Function Name : RTC_display
* Description   : Get digital clock info.
* Input         : - type: digital clock info sources
				  - buff: digital clock info
* Output        : None
* Return        : None
************************************************************************************/
void RTC_display(uint8_t type, uint8_t *buff)
{
	uint16_t p_add, p_len, pointer;
	uint16_t x, y, w, h; // Display box
	uint16_t simage, eimage;
	uint8_t mode = 0;

	if (type == 0) // instruction information source is configuration file
	{
		x = buff[5] + (buff[6] << 8);
		y = buff[7] + (buff[8] << 8);
		simage = buff[9] + (buff[10] << 8);
		eimage = buff[11] + (buff[12] << 8);
		mode = buff[13];
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		x = var[pointer + 1] + (var[pointer + 2] << 8);
		y = var[pointer + 3] + (var[pointer + 4] << 8);
		simage = var[pointer + 5] + (var[pointer + 6] << 8);
		eimage = var[pointer + 7] + (var[pointer + 8] << 8);
		mode = var[pointer + 9];
	}

	gRTC_Info[RTC_num].x = x;
	gRTC_Info[RTC_num].y = y;
	gRTC_Info[RTC_num].ID_start = simage;
	gRTC_Info[RTC_num].mode = mode;

	if (Pop_up_flag == 1)
	{
		gRTC_Info[RTC_num].x += Pop_up_x;
		gRTC_Info[RTC_num].y += Pop_up_y;
	}

	Display_RTC(&gRTC_Info[RTC_num], 0);
	RTC_num++;
}

void show_RTC(void)
{
	if (RTC_num > 0 && RTC_flag == 1)
	{
		RTC_flag = 0;
		for (uint8_t i = 0; i < RTC_num; i++)
		{
			Display_RTC(&gRTC_Info[i], 1);
		}
	}
}

uint8_t Clock_num = 0;
uint8_t Clock_flag = 0;
Clock_Info gClock_Info[CLOCK_SIZE];
uint32_t Lay_temp = 0;
/***********************************************************************************
* Function Name : Display_Clock
* Description   : Show analog clock.
* Input         : - num: analog clock number
				  - status: analog clock status
* Output        : None
* Return        : None
************************************************************************************/
uint8_t Display_Clock(uint8_t num, uint8_t status)
{
	uint8_t hour, min, sec;
	uint8_t hour_temp;

	hour = calendar.hour;
	min = calendar.min;
	sec = calendar.sec;

	hour = hour % 12;

	if (gClock_Info[num].Image_BG < addr_index[11]) // ICON is available
	{
		if (gClock_Info[num].len_pic != 0 && gClock_Info[num].flag_pic != 0xFF) // ICON is not empty
		{
			// In the keyboard input interface
			if (DioKb_flag == 1)
			{
				if (!(gClock_Info[num].x_pic > gDio_Info[Dio_num].Xe || (gClock_Info[num].x_pic + gClock_Info[num].w_pic) < gDio_Info[Dio_num].Xs || gClock_Info[num].y_pic > gDio_Info[Dio_num].Ye || (gClock_Info[num].y_pic + gClock_Info[num].h_pic) < gDio_Info[Dio_num].Ys))
				{
					return 0;
				}
			}
			else if (AioKb_flag == 1)
			{
				if (!(gClock_Info[num].x_pic > gAio_Info[Aio_num].Xe || (gClock_Info[num].x_pic + gClock_Info[num].w_pic) < gAio_Info[Aio_num].Xs || gClock_Info[num].y_pic > gAio_Info[Aio_num].Ye || (gClock_Info[num].y_pic + gClock_Info[num].h_pic) < gAio_Info[Aio_num].Ys))
				{
					return 0;
				}
			}
			else if (GBKioKb_flag == 1)
			{
				if (!(gClock_Info[num].x_pic > gGBKio_Info[GBKio_num].Xe || (gClock_Info[num].x_pic + gClock_Info[num].w_pic) < gGBKio_Info[GBKio_num].Xs || gClock_Info[num].y_pic > gGBKio_Info[GBKio_num].Ye || (gClock_Info[num].y_pic + gClock_Info[num].h_pic) < gGBKio_Info[GBKio_num].Ys))
				{
					return 0;
				}
			}

			// full-screen background
			if (gClock_Info[num].flag_pic == 1 || gClock_Info[num].flag_pic == 2)
			{
//				LT268_pic_to_buffer(0, 0, gClock_Info[num].w_pic, m_PngData,
//									gClock_Info[num].x_pic, gClock_Info[num].y_pic, LCD_XSIZE_TFT, FullScreen_addr,
//									gClock_Info[num].w_pic, gClock_Info[num].h_pic, FullScreen_flag);
				LT268_BG_to_buffer(0, 0, gClock_Info[num].w_pic, m_PngData,
									gClock_Info[num].x_pic, gClock_Info[num].y_pic,gClock_Info[num].w_pic, gClock_Info[num].h_pic);
			}

			// clock background
			LT268_pic_to_buffer(0, 0, gClock_Info[num].w_pic, m_PngData,
								0, 0, gClock_Info[num].w_pic, gClock_Info[num].addr_pic,
								gClock_Info[num].w_pic, gClock_Info[num].h_pic, gClock_Info[num].flag_pic);

			// Pointer of clock
			DrawClockPointer(gClock_Info[num].x, gClock_Info[num].y, hour * 30 + min * 30 / 60, gClock_Info[num].L_hour, gClock_Info[num].S_hour, gClock_Info[num].Color_hour, gClock_Info[num].W_hour,
							 gClock_Info[num].x, gClock_Info[num].y, min * 6 + sec * 6 / 60, gClock_Info[num].L_min, gClock_Info[num].S_min, gClock_Info[num].Color_min, gClock_Info[num].W_min, // min*6+sec*6/60
							 gClock_Info[num].x, gClock_Info[num].y, sec * 6, gClock_Info[num].L_sec, gClock_Info[num].S_sec, gClock_Info[num].Color_sec, gClock_Info[num].W_sec,
							 gClock_Info[num].x_pic, gClock_Info[num].y_pic, gClock_Info[num].w_pic, gClock_Info[num].h_pic);

			// center ICON
			if (gClock_Info[num].len_cen != 0 && gClock_Info[num].flag_cen != 0xFF)
			{
				pic_flag = gClock_Info[num].flag_cen;

				LT268_pic_to_buffer(gClock_Info[num].x_cen - gClock_Info[num].x_pic, gClock_Info[num].y_cen - gClock_Info[num].y_pic, gClock_Info[num].w_pic, m_PngData,
									0, 0, gClock_Info[num].w_cen, gClock_Info[num].addr_cen,
									gClock_Info[num].w_cen, gClock_Info[num].h_cen, gClock_Info[num].flag_cen);
			}

			LT268_buffer_to_TFT(0, 0, gClock_Info[num].w_pic, m_PngData,
								gClock_Info[num].x_pic, gClock_Info[num].y_pic, gClock_Info[num].w_pic, gClock_Info[num].h_pic);
		}
	}
}

/***********************************************************************************
* Function Name	: Clock_display
* Description   : Get analog clock info.
* Input         : - type: analog clock info sources
				  - buff: analog clock info
* Output        : None
* Return        : None
************************************************************************************/
void Clock_display(uint8_t type, uint8_t *buff)
{
	uint8_t buff1[12] = {0};
	uint8_t L_hour, S_hour, W_hour, L_min, S_min, W_min, L_sec, S_sec, W_sec;
	uint16_t p_add, p_len, pointer;
	uint16_t x, y, image, image_cen;
	uint16_t r, g, b;
	uint32_t Color_hour = 0, Color_min = 0, Color_sec = 0;
	if (type == 0) // Instruction information source is configuration file
	{
		x = buff[5] + (buff[6] << 8);
		y = buff[7] + (buff[8] << 8);
		image = buff[9] + (buff[10] << 8);
		L_hour = buff[11];
		S_hour = buff[12];
		W_hour = buff[13];
		Color_hour = buff[14] + (buff[15] << 8) + (buff[16] << 16);
		L_min = buff[17];
		S_min = buff[18];
		W_min = buff[19];
		Color_min = buff[20] + (buff[21] << 8) + (buff[22] << 16);
		L_sec = buff[23];
		S_sec = buff[24];
		W_sec = buff[25];
		Color_sec = buff[26] + (buff[27] << 8) + (buff[28] << 16);
		image_cen = buff[29] + (buff[30] << 8);
	}
	else if (type == 1) // Instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		x = var[pointer + 1] + (var[pointer + 2] << 8);
		y = var[pointer + 3] + (var[pointer + 4] << 8);
		image = var[pointer + 5] + (var[pointer + 6] << 8);
		L_hour = var[pointer + 7];
		S_hour = var[pointer + 8];
		W_hour = var[pointer + 9];
		Color_hour = var[pointer + 10] + (var[pointer + 11] << 8) + (var[pointer + 12] << 16);
		L_min = var[pointer + 13];
		S_min = var[pointer + 14];
		W_min = var[pointer + 15];
		Color_min = var[pointer + 16] + (var[pointer + 17] << 8) + (var[pointer + 18] << 16);
		L_sec = var[pointer + 19];
		S_sec = var[pointer + 20];
		W_sec = var[pointer + 21];
		Color_sec = var[pointer + 22] + (var[pointer + 23] << 8) + (var[pointer + 24] << 16);
		image_cen = var[pointer + 25] + (var[pointer + 26] << 8);
	}
	
	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
	}
	gClock_Info[Clock_num].x_pic = x;
	gClock_Info[Clock_num].y_pic = y;
	gClock_Info[Clock_num].Image_BG = image;
	gClock_Info[Clock_num].L_hour = L_hour;
	gClock_Info[Clock_num].S_hour = S_hour;
	gClock_Info[Clock_num].W_hour = W_hour;
	gClock_Info[Clock_num].Color_hour = Color_hour;
	gClock_Info[Clock_num].L_min = L_min;
	gClock_Info[Clock_num].S_min = S_min;
	gClock_Info[Clock_num].W_min = W_min;
	gClock_Info[Clock_num].Color_min = Color_min;
	gClock_Info[Clock_num].L_sec = L_sec;
	gClock_Info[Clock_num].S_sec = S_sec;
	gClock_Info[Clock_num].W_sec = W_sec;
	gClock_Info[Clock_num].Color_sec = Color_sec;

	if (image < addr_index[11]) // ICON is not empty
	{
		LT_ReadFlash_UI(buff1, addr_index[10] + 12 * image + multi_language * 12 * addr_index[11], 12);

		gClock_Info[Clock_num].addr_pic = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		gClock_Info[Clock_num].w_pic = buff1[4] + (buff1[5] << 8);
		gClock_Info[Clock_num].h_pic = buff1[6] + (buff1[7] << 8);
		gClock_Info[Clock_num].len_pic = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		gClock_Info[Clock_num].flag_pic = buff1[11];
		gClock_Info[Clock_num].x = x + gClock_Info[Clock_num].w_pic / 2;
		gClock_Info[Clock_num].y = y + gClock_Info[Clock_num].h_pic / 2;

		if (image_cen < addr_index[11]) // ICON is not empty
		{
			LT_ReadFlash_UI(buff1, addr_index[10] + 12 * image_cen + multi_language * 12 * addr_index[11], 12);

			gClock_Info[Clock_num].addr_cen = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
			gClock_Info[Clock_num].w_cen = buff1[4] + (buff1[5] << 8);
			gClock_Info[Clock_num].h_cen = buff1[6] + (buff1[7] << 8);
			gClock_Info[Clock_num].len_cen = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
			gClock_Info[Clock_num].flag_cen = buff1[11];
			gClock_Info[Clock_num].x_cen = gClock_Info[Clock_num].x - gClock_Info[Clock_num].w_cen / 2;
			gClock_Info[Clock_num].y_cen = gClock_Info[Clock_num].y - gClock_Info[Clock_num].h_cen / 2;
		}
	}

	Display_Clock(Clock_num, 0);
	Clock_num++;
	
}

void show_Clock(void)
{
	if (Clock_num > 0 && Clock_flag == 1)
	{
		Clock_flag = 0;
		for (uint8_t i = 0; i < Clock_num; i++)
		{
			Display_Clock(i, 1);
		}
	}
}

/*******************************************************************************
 * Function Name : LT_Print_zk_Font_Scroll
 * Description   : txt scroll.
 * Input         :
 * Output        : None
 * Return        : None
 ********************************************************************/
uint16_t LT_Print_zk_Font_Scroll(
	uint16_t encode // encoding type     0:GB2312  1:GBK  2:BIG5  3:UNICODE  4:ASCII
	,
	uint32_t FlashAddr // Font source address(exSpiFlash)
	,
	uint32_t ShowAddr // Displays the address of the layer
	,
	uint16_t width // Display the width of the layer
	,
	uint8_t W_Size //  font width
	,
	uint8_t H_Size // font height
	,
	uint8_t Alignment // Alignment
	,
	uint32_t FontColor // The foreground color of the font
	,
	uint32_t BackColor // The background color of the font
	,
	uint8_t enbackcolor // Background color enable, 0:disable  1:enable
	,
	uint8_t mix // mix mode, 0:with fullscreen interface   1:with specific pictures(Text box needs to be fully included)
	,
	_PICINFO mixpic // mix picture info
	,
	uint16_t Xs // Text box start x position
	,
	uint16_t Ys // Text box start Y position
	,
	uint16_t Xe // Text box end x position
	,
	uint16_t Ye // Text box end y position
	,
	uint8_t dis_x // The interval between two adjacent fonts on the x-axis
	,
	uint8_t dis_y // The interval between two adjacent fonts on the y-axis
	,
	uint8_t *c // Address of text
	,
	uint16_t len_max // max lenght of text
	,
	uint8_t num // Scroll_num
	,
	uint16_t x_off // x offset
)
{
	uint16_t temp = 0, temp_H = 0, temp_L = 0;
	uint32_t i = 0;
	uint16_t X_start = 0, Y_start = 0;
	uint8_t gray, gray_bit;
	uint16_t disp_w = 0, disp_i = 0;
	uint16_t temp_w;
	uint16_t box_w = Xe - Xs + 1, box_h = Ye - Ys + 1;
	uint16_t buf_w = 0, buf_h = Ye - Ys + 1;
	uint8_t unicode_w;
	uint16_t font_byte; // bytes of a single font
	
	LT_ReadFlash_UI(Ascii_w, FlashAddr + 9, 95);
	LT_ReadFlash_UI(&gray, FlashAddr + 8, 1);
	
	if (gray == 0)
		gray_bit = 1;
	else if (gray == 1)
		gray_bit = 2;
	else if (gray == 2)
		gray_bit = 4;

	i = 0;
	if (encode == 4) // ASCII
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				buf_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else
				break;
		}
	}
	else if (encode == 0)
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				buf_w += Ascii_w[c[i] - 0x20] + dis_x + 2;
				i++;
			}
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
			{
				buf_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 1)
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				buf_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
			{
				buf_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 2)
	{
		while (1)
		{
			if (c[i] < 128 && c[i] > 0x00)
			{
				buf_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
			{
				buf_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 3)
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1)
		{
			unicode = (c[i] << 8) + c[i + 1];
			if (unicode == 0x0000)
				break;
			else if (unicode < 128 && unicode > 0x00)
			{
				buf_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				buf_w += W_Size + dis_x;
				i += 2;
			}
			else
				break;
		}
	}
	else if (encode == 6)
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];
		
		font_byte = (W_Size * gray_bit + 7) / 8 * H_Size;

		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1)
		{
			unicode = (c[i] << 8) + c[i + 1];
			if (unicode == 0x0000)
				break;
			if (unicode < 128 && unicode > 0x00)
			{
				buf_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				LT_ReadFlash_UI(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - start_code) * (font_byte + 1), 1);
				buf_w += (unicode_w + dis_x);
				i += 2;
			}
			else
				break;
		}
	}

	if (buf_w > box_w)
	{
		buf_w = buf_w + gScroll_Info[num].gap;
		gScroll_Info[num].flag = 1;
	}
	else if (buf_w + gScroll_Info[num].gap > box_w)
	{
		buf_w = box_w + gScroll_Info[num].gap;
		gScroll_Info[num].flag = 1;
	}
	else
	{
		if (gScroll_Info[num].scroll_en)
		{
			buf_w = box_w + gScroll_Info[num].gap;
			gScroll_Info[num].flag = 1;
		}
		else
		{
			if (Alignment == 0)
			{
				X_start = 0;
				
			}
			else if (Alignment == 1)
			{
				X_start = (box_w - buf_w) / 2;
				
			}
			else if (Alignment == 2)
			{
				X_start = box_w - buf_w;
			}

			
			buf_w = box_w;
			gScroll_Info[num].flag = 0;
		}
	}

	Y_start = (Ye-Ys-H_Size)/2;
	
	if (buf_w * buf_h * 2 > MAX_PixelSize)
		return 1;


	gScroll_Info[num].buf_w = buf_w;
	//	printf("buf_w,buf_h,box_w,box_h    %d    %d   %d   %d    \r\n",buf_w,buf_h,box_w,box_h);
	//	printf("x_off  gScroll_Info[num].w   %d    %d   %d   %d    \r\n \r\n",x_off,gScroll_Info[num].w,box_w,box_h);

	if ((x_off + box_w) <= buf_w)
	{
		if (enbackcolor)
		{
//			LT268_TFT_FillColor_Buffer2(x_off, 0, buf_w, m_PngData, box_w, box_h, BackColor);
			// debug
//			if(x_off + box_w - (buf_w - gScroll_Info[num].gap) > 0)
//			{
//				if(x_off + box_w - (buf_w - gScroll_Info[num].gap) > box_w)
//				LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData,
//									Xs, Ys, LCD_XSIZE_TFT, FullScreen_addr,
//									box_w, box_h, FullScreen_flag);
//				else
//				LT268_TFT_FillColor_Buffer2(x_off, 0, buf_w, m_PngData, box_w, box_h, BackColor);
//				LT268_pic_to_buffer(buf_w - gScroll_Info[num].gap, 0, buf_w, m_PngData,
//									Xs - x_off + (buf_w - gScroll_Info[num].gap), Ys, LCD_XSIZE_TFT, FullScreen_addr,
//									x_off + box_w - (buf_w - gScroll_Info[num].gap), box_h, FullScreen_flag);
//			}
//			else
//				LT268_TFT_FillColor_Buffer2(x_off, 0, buf_w, m_PngData, box_w, box_h, BackColor);
				LT268_BG_to_Pure(x_off, 0, buf_w, m_PngData,
								 box_w, box_h, BackColor);
		}
		else
		{
			if (mix == 0)
			{
//				LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData,
//									Xs, Ys, LCD_XSIZE_TFT, FullScreen_addr,
//									box_w, box_h, FullScreen_flag);
				LT268_BG_to_buffer(x_off, 0, buf_w, m_PngData,
									Xs, Ys,box_w, box_h);
			}
			else
			{
				if (mixpic.flag == 0x10)
				{
//					LT268_TFT_FillColor_Buffer2(x_off, 0, buf_w, m_PngData, box_w, box_h, mixpic.len);
					LT268_BG_to_Pure(x_off, 0, buf_w, m_PngData,
									 box_w, box_h, mixpic.len);
				}
				else
				{
					if (mixpic.flag != 0)
//						LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData,
//											Xs, Ys, LCD_XSIZE_TFT, FullScreen_addr,
//											box_w, box_h, FullScreen_flag);
						LT268_BG_to_buffer(x_off, 0, buf_w, m_PngData,
											Xs, Ys, box_w, box_h);
					
					LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData, Xs - mixpic.x, Ys - mixpic.y, mixpic.w, mixpic.addr, box_w, box_h, mixpic.flag);
				}
			}
		}
	}
	else
	{
		if (enbackcolor)
		{
//			LT268_TFT_FillColor_Buffer2(x_off, 0, buf_w, m_PngData, buf_w - x_off, box_h, BackColor);
//			LT268_TFT_FillColor_Buffer2(0, 0, buf_w, m_PngData, box_w - (buf_w - x_off), box_h, BackColor);
			// debug
//			LT268_TFT_FillColor_Buffer2(0, 0, buf_w, m_PngData, buf_w, box_h, BackColor);
			LT268_BG_to_Pure(0, 0, buf_w, m_PngData,
							 buf_w, box_h, BackColor);
//			if(x_off < buf_w - gScroll_Info[num].gap)
//			{
//				LT268_pic_to_buffer(buf_w - gScroll_Info[num].gap, 0, buf_w, m_PngData,
//						Xs + buf_w - gScroll_Info[num].gap - x_off, Ys, LCD_XSIZE_TFT, FullScreen_addr,
//						gScroll_Info[num].gap, box_h, FullScreen_flag);
//			}
//			else
//			{
//				LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData,
//						Xs, Ys, LCD_XSIZE_TFT, FullScreen_addr,
//						buf_w - x_off, box_h, FullScreen_flag);
//			}
			
		}
		else
		{
			if (mix == 0)
			{
//				LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData,
//									Xs, Ys, LCD_XSIZE_TFT, FullScreen_addr,
//									buf_w - x_off, box_h, FullScreen_flag);
//				LT268_pic_to_buffer(0, 0, buf_w, m_PngData,
//									Xs + buf_w - x_off, Ys, LCD_XSIZE_TFT, FullScreen_addr,
//									box_w - (buf_w - x_off), box_h, FullScreen_flag);
				
				LT268_BG_to_buffer(x_off, 0, buf_w, m_PngData,
									Xs, Ys, buf_w - x_off, box_h);
				LT268_BG_to_buffer(0, 0, buf_w, m_PngData,
									Xs + buf_w - x_off, Ys, box_w - (buf_w - x_off), box_h);
				
			}
			else
			{
				if (mixpic.flag == 0x10)
				{
//					LT268_TFT_FillColor_Buffer2(x_off, 0, buf_w, m_PngData, buf_w - x_off, box_h, mixpic.len);
//					LT268_TFT_FillColor_Buffer2(0, 0, buf_w, m_PngData, box_w - (buf_w - x_off), box_h, mixpic.len);
//					LT268_TFT_FillColor_Buffer2(0, 0, buf_w, m_PngData, buf_w, box_h, mixpic.len);
					LT268_BG_to_Pure(0, 0, buf_w, m_PngData,
									 buf_w, box_h, mixpic.len);
				}
				else
				{
					if (mixpic.flag != 0)
					{
//						LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData,
//											Xs, Ys, LCD_XSIZE_TFT, FullScreen_addr,
//											buf_w - x_off, box_h, FullScreen_flag);
//						LT268_pic_to_buffer(0, 0, buf_w, m_PngData,
//											Xs + buf_w - x_off, Ys, LCD_XSIZE_TFT, FullScreen_addr,
//											box_w - (buf_w - x_off), box_h, FullScreen_flag);
						LT268_BG_to_buffer(x_off, 0, buf_w, m_PngData,
											Xs, Ys, buf_w - x_off, box_h);
						LT268_BG_to_buffer(0, 0, buf_w, m_PngData,
											Xs + buf_w - x_off, Ys, box_w - (buf_w - x_off), box_h);
					}
					LT268_pic_to_buffer(x_off, 0, buf_w, m_PngData,
										Xs - mixpic.x, Ys - mixpic.y, mixpic.w, mixpic.addr,
										buf_w - x_off, box_h, mixpic.flag);
					LT268_pic_to_buffer(0, 0, buf_w, m_PngData,
										Xs - mixpic.x + buf_w - x_off, Ys - mixpic.y, mixpic.w, mixpic.addr,
										box_w - (buf_w - x_off), box_h, mixpic.flag);
				}
			}
		}
	}

	i = 0;

	if (encode == 4) // ASCII
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{

			if (c[i] < 128 && c[i] > 0x00)
				temp_w = (Ascii_w[c[i] - 0x20] + dis_x + 2);
			// else if(c[i]==0x0A)                temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			if ((disp_w + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (Y_start + H_Size > box_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i; disp_i++)
				{
					LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
													FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
													X_start, Y_start, buf_w, m_PngData);

					X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
		}
	}
	else if (encode == 0) // GB2312
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
				temp_w = W_Size + dis_x;
			// else if(c[i]==0x0A)                temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			if ((disp_w + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (Y_start + H_Size > box_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{
						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
														X_start, Y_start, buf_w, m_PngData);

						X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0xa1 && c[disp_i] != 0xFF)
					{
						LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, &c[disp_i],
														X_start, Y_start, buf_w, m_PngData);

						X_start += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i] != 0xFF)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 1) // GBK
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
				temp_w = W_Size + dis_x;
			// else if(c[i]==0x0A)                									temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			if ((disp_w + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (Y_start + H_Size > box_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{

						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
														X_start, Y_start, buf_w, m_PngData);

						X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0x81 && c[disp_i + 1] >= 0x40 && c[disp_i] != 0xFF)
					{

						LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, &c[disp_i],
														X_start, Y_start, buf_w, m_PngData);

						X_start += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0x81 && c[i + 1] >= 0x40 && c[i] != 0xFF)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 2) // BIG
	{
		while (1) // Automatic exit when meeting the end-of-transmission
		{
			if (c[i] < 128 && c[i] > 0x00)
				temp_w = Ascii_w[c[i] - 0x20] + dis_x + 2;
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
				temp_w = W_Size + dis_x;
			// else if(c[i]==0x0A)                									temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			if ((disp_w + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (Y_start + H_Size > box_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					if (c[disp_i] < 128 && c[disp_i] > 0x00)
					{

						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[c[disp_i] - 0x20] + dis_x + 2, &c[disp_i],
														X_start, Y_start, buf_w, m_PngData);

						X_start += (Ascii_w[c[disp_i] - 0x20] + dis_x + 2);
						disp_i++;
					}
					else if (c[disp_i] >= 0xa1 && c[disp_i + 1] >= 0x40)
					{

						LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, &c[disp_i],
														X_start, Y_start, buf_w, m_PngData);

						X_start += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i++;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (c[i] == 0x0A)
					i++;
			}
			else if (c[i] < 128 && c[i] > 0x00)
			{
				disp_w += (Ascii_w[c[i] - 0x20] + dis_x + 2);
				i++;
			}
			else if (c[i] >= 0xa1 && c[i + 1] >= 0x40)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 3)
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			
			if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode == 0x0000)
				len_max = i;
			else if (unicode >= start_code && unicode <= end_code)
				temp_w = W_Size + dis_x;
			// else if(c[i]==0x0A)                									temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			if ((disp_w + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (Y_start + H_Size > box_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					unicode_temp = (c[disp_i] << 8) + c[disp_i + 1];
					if (unicode_temp < 128 && unicode_temp > 0x00)
					{

						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[unicode_temp - 0x20] + dis_x + 2, &c[disp_i + 1],
														X_start, Y_start, buf_w, m_PngData);

						X_start += (Ascii_w[unicode_temp - 0x20] + dis_x + 2);
						disp_i += 2;
					}
					else if (unicode_temp >= start_code && unicode_temp <= end_code)
					{

						LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, (uint8_t *)(unicode_temp - start_code),
														X_start, Y_start, buf_w, m_PngData);

						X_start += (W_Size + dis_x);
						disp_i += 2;
					}
					else
						disp_i += 2;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
					i += 2;
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += (Ascii_w[unicode - 0x20] + dis_x + 2);
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += (W_Size + dis_x);
				i += 2;
			}
		}
	}
	else if (encode == 6)
	{
		uint16_t unicode = 0, unicode_temp = 0;
		uint16_t start_code = 0, end_code = 0;
		uint8_t buff_code[4];

		LT_ReadFlash_UI(buff_code, FlashAddr + 4, 4);
		start_code = buff_code[0] + (buff_code[1] << 8);
		end_code = buff_code[2] + (buff_code[3] << 8);

		while (1) // Automatic exit when meeting the end-of-transmission
		{
			unicode = (c[i] << 8) + c[i + 1];

			if (unicode < 128 && unicode > 0x00)
				temp_w = Ascii_w[unicode - 0x20] + dis_x + 2;
			else if (unicode == 0x0000)
				len_max = i;
			else if (unicode >= start_code && unicode <= end_code)
			{
				LT_ReadFlash_UI(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode - start_code) * (font_byte + 1), 1);
				temp_w = unicode_w + dis_x;
			}
			// else if(c[i]==0x0A)                									temp_w = 0;
			else
				len_max = i; // coding error or max len (Exit after entering the display)

			if ((disp_w + temp_w) > (buf_w) || c[i] == 0x0A || i >= len_max) // Text box X-axis display coordinates out of range
			{
				if (Y_start + H_Size > box_h)
					break; // Text box Y-axis is out of range

				for (; disp_i < i;)
				{
					unicode_temp = (c[disp_i] << 8) + c[disp_i + 1];
					if (unicode_temp < 128 && unicode_temp > 0x00)
					{

						LT268_GrayScaleFont_dislay_BUFF(4, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, Ascii_w[unicode_temp - 0x20] + dis_x + 2, &c[disp_i + 1],
														X_start, Y_start, buf_w, m_PngData);

						X_start += (Ascii_w[unicode_temp - 0x20] + dis_x + 2);
						disp_i += 2;
					}
					else if (unicode_temp >= start_code && unicode_temp <= end_code)
					{

						LT268_GrayScaleFont_dislay_BUFF(encode, FlashAddr, W_Size, H_Size, gray,
														FontColor, BackColor, enbackcolor, W_Size + dis_x, (uint8_t *)(unicode_temp - start_code),
														X_start, Y_start, buf_w, m_PngData);

						LT_ReadFlash_UI(&unicode_w, FlashAddr + 104 + 95 * font_byte + (unicode_temp - start_code) * (font_byte + 1), 1);

						X_start += (unicode_w + dis_x);
						disp_i += 2;
					}
					else
						disp_i += 2;
				}

				data_w = disp_w; // Record width
				disp_w = 0;
				Y_start += H_Size;
				if (i >= len_max)
					break;
				else if (unicode == 0x000A)
					i += 2;
			}
			else if (unicode < 128 && unicode > 0x00)
			{
				disp_w += temp_w;
				i += 2;
			}
			else if (unicode >= start_code && unicode <= end_code)
			{
				disp_w += temp_w;
				i += 2;
			}
		}
	}
	return 0;
}

uint8_t Scroll_num = 0;
uint8_t Scroll_flag = 0;
Scroll_Info gScroll_Info[SCROLL_SIZE];
/***********************************************************************************
* Function Name	: text_scroll
* Description	: Get text scroll info.
* Input         : - type: text scroll info sources
				  - buff: text scroll info
* Output        : None
* Return        : None
************************************************************************************/
void text_scroll(uint8_t type, uint8_t *buff)
{
	uint16_t xs, ys, xe, ye; // Display box
	uint8_t Zk_id, w, h;	 // Font ID, font width and height
	uint8_t encode;			 // Font encoding type
	uint8_t Alignment;
	uint32_t fcolor, bcolor; // The foreground color of the font,The background color of the font
	uint16_t p_add, p_len, pointer;
	uint32_t zk_addr;
	uint8_t buff1[4] = {0};
	uint8_t scroll_en = 0;
	uint8_t t_d = 0;
	uint16_t gap = 0;
	uint8_t transparent = 0;

	if (type == 0) // instruction information source is configuration file
	{
		p_add = (buff[5] + (buff[6] << 8)) * 2;
		p_len = buff[15] + (buff[16] << 8);
		xs = buff[7] + (buff[8] << 8);
		ys = buff[9] + (buff[10] << 8);
		xe = buff[11] + (buff[12] << 8);
		ye = buff[13] + (buff[14] << 8);
		Zk_id = buff[17];
		w = buff[18];
		h = buff[19];
		encode = buff[20];
		Alignment = buff[21];
		scroll_en = buff[22];
		fcolor = buff[23] + (buff[24] << 8) + (buff[25] << 16);
		t_d = buff[26];
		bcolor = buff[27] + (buff[28] << 8) + (buff[29] << 16);
		gap = buff[30] + (buff[31] << 8);
		transparent = buff[32];
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		p_add = (var[pointer + 1] + (var[pointer + 2] << 8)) * 2;
		p_len = var[pointer + 11] + (var[pointer + 12] << 8);
		xs = var[pointer + 3] + (var[pointer + 4] << 8);
		ys = var[pointer + 5] + (var[pointer + 6] << 8);
		xe = var[pointer + 7] + (var[pointer + 8] << 8);
		ye = var[pointer + 9] + (var[pointer + 10] << 8);
		Zk_id = var[pointer + 13];
		w = var[pointer + 14];
		h = var[pointer + 15];
		encode = var[pointer + 16];
		Alignment = var[pointer + 17];
		scroll_en = var[pointer + 18];
		fcolor = var[pointer + 19] + (var[pointer + 20] << 8) + (var[pointer + 21] << 16);
		t_d = var[pointer + 22];
		bcolor = var[pointer + 23] + (var[pointer + 24] << 8) + (var[pointer + 25] << 16);
		gap = var[pointer + 26] + (var[pointer + 27] << 8);
		transparent = var[pointer + 28];
	}
	
	if (Pop_up_flag == 1) // Popup offset
	{
		xs += Pop_up_x;
		ys += Pop_up_y;
		xe += Pop_up_x;
		ye += Pop_up_y;
	}
	
	LT_ReadFlash_UI(buff1, addr_index[2] + Zk_id * 8, 4);
	zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);

	gScroll_Info[Scroll_num].x = xs;
	gScroll_Info[Scroll_num].y = ys;
	gScroll_Info[Scroll_num].w = xe - xs + 1;
	gScroll_Info[Scroll_num].h = ye - ys + 1;
	gScroll_Info[Scroll_num].t_d = t_d;
	// gScroll_Info[Scroll_num].cnt = gScroll_Info[Scroll_num].w;
	gScroll_Info[Scroll_num].cnt = 0;
	gScroll_Info[Scroll_num].t_c = 0;
	gScroll_Info[Scroll_num].gap = gap;
	gScroll_Info[Scroll_num].transparent = transparent;
	gScroll_Info[Scroll_num].scroll_en = scroll_en;
	gScroll_Info[Scroll_num].bcolor = bcolor;
	gScroll_Info[Scroll_num].encode = encode;
	gScroll_Info[Scroll_num].zk_addr = zk_addr;
	gScroll_Info[Scroll_num].fcolor = fcolor;
	gScroll_Info[Scroll_num].Alignment = Alignment;
	gScroll_Info[Scroll_num].xe = xe;
	gScroll_Info[Scroll_num].ye = ye;
	gScroll_Info[Scroll_num].len_max = p_len * 2;
	gScroll_Info[Scroll_num].c = &var[p_add];
	gScroll_Info[Scroll_num].font_w = w;
	gScroll_Info[Scroll_num].font_h = h;

	LT_Print_zk_Font_Scroll(encode, zk_addr,
							LAY_BUFF1, LCD_XSIZE_TFT, w, h, Alignment, fcolor, bcolor, transparent, 0, PICINFO[0],
							xs, ys, xe, ye,
							0, 0, gScroll_Info[Scroll_num].c, p_len * 2,
							Scroll_num, 0);

	LT268_buffer_to_TFT(0, 0, gScroll_Info[Scroll_num].buf_w, m_PngData,
						gScroll_Info[Scroll_num].x, gScroll_Info[Scroll_num].y, gScroll_Info[Scroll_num].w, gScroll_Info[Scroll_num].h);
}

uint8_t text_scroll_Once(uint8_t num)
{
	// In the keyboard input interface
	if (DioKb_flag == 1)
	{
		if (!(gScroll_Info[num].x > gDio_Info[Dio_num].Xe || (gScroll_Info[num].x + gScroll_Info[num].w) < gDio_Info[Dio_num].Xs ||
			  gScroll_Info[num].y > gDio_Info[Dio_num].Ye || (gScroll_Info[num].y + gScroll_Info[num].h) < gDio_Info[Dio_num].Ys))
		{
			return 0;
		}
	}
	else if (AioKb_flag == 1)
	{
		if (!(gScroll_Info[num].x > gAio_Info[Aio_num].Xe || (gScroll_Info[num].x + gScroll_Info[num].w) < gAio_Info[Aio_num].Xs ||
			  gScroll_Info[num].y > gAio_Info[Aio_num].Ye || (gScroll_Info[num].y + gScroll_Info[num].h) < gAio_Info[Aio_num].Ys))
		{
			return 0;
		}
	}
	else if (GBKioKb_flag == 1)
	{
		if (!(gScroll_Info[num].x > gGBKio_Info[GBKio_num].Xe || (gScroll_Info[num].x + gScroll_Info[num].w) < gGBKio_Info[GBKio_num].Xs ||
			  gScroll_Info[num].y > gGBKio_Info[GBKio_num].Ye || (gScroll_Info[num].y + gScroll_Info[num].h) < gGBKio_Info[GBKio_num].Ys))
		{
			return 0;
		}
	}

	if (gScroll_Info[num].cnt + gScroll_Info[num].w <= gScroll_Info[num].buf_w)
	{
		LT_Print_zk_Font_Scroll(gScroll_Info[num].encode, gScroll_Info[num].zk_addr,
								LAY_BUFF1, LCD_XSIZE_TFT, gScroll_Info[num].font_w, gScroll_Info[num].font_h, gScroll_Info[num].Alignment,
								gScroll_Info[num].fcolor, gScroll_Info[num].bcolor, gScroll_Info[num].transparent, 0, PICINFO[0],
								gScroll_Info[num].x, gScroll_Info[num].y, gScroll_Info[num].xe, gScroll_Info[num].ye,
								0, 0, gScroll_Info[num].c, gScroll_Info[num].len_max,
								num, gScroll_Info[num].cnt);

		LT268_buffer_to_TFT(gScroll_Info[num].cnt, 0, gScroll_Info[num].buf_w, m_PngData,
							gScroll_Info[num].x, gScroll_Info[num].y, gScroll_Info[num].w, gScroll_Info[num].h);
	}
	else
	{
		LT_Print_zk_Font_Scroll(gScroll_Info[num].encode, gScroll_Info[num].zk_addr,
								LAY_BUFF1, LCD_XSIZE_TFT, gScroll_Info[num].font_w, gScroll_Info[num].font_h, gScroll_Info[num].Alignment,
								gScroll_Info[num].fcolor, gScroll_Info[num].bcolor, gScroll_Info[num].transparent, 0, PICINFO[0],
								gScroll_Info[num].x, gScroll_Info[num].y, gScroll_Info[num].xe, gScroll_Info[num].ye,
								0, 0, gScroll_Info[num].c, gScroll_Info[num].len_max,
								num, gScroll_Info[num].cnt);

		LT268_buffer_to_TFT(gScroll_Info[num].cnt, 0, gScroll_Info[num].buf_w, m_PngData,
							gScroll_Info[num].x, gScroll_Info[num].y, gScroll_Info[num].buf_w - gScroll_Info[num].cnt, gScroll_Info[num].h);

		LT268_buffer_to_TFT(0, 0, gScroll_Info[num].buf_w, m_PngData,
							gScroll_Info[num].x + gScroll_Info[num].buf_w - gScroll_Info[num].cnt, gScroll_Info[num].y,
							gScroll_Info[num].w - (gScroll_Info[num].buf_w - gScroll_Info[num].cnt), gScroll_Info[num].h);
	}
	//	printf("gScroll_Info[num].cnt,gScroll_Info[num].buf_w,        %d    %d \r\n",gScroll_Info[num].cnt,gScroll_Info[num].buf_w);

	gScroll_Info[num].cnt += 1;
	if (gScroll_Info[num].cnt >= gScroll_Info[num].buf_w)
		gScroll_Info[num].cnt = 0;
}

void scroll_text(void)
{
	uint8_t i;
	if (Scroll_num && Scroll_flag)
	{
		Scroll_flag = 0;
		for (i = 0; i < Scroll_num; i++)
			gScroll_Info[i].t_c++;
		for (i = 0; i < Scroll_num; i++)
		{
			// When a window timing time expires, scroll 1 pixel
			if ((gScroll_Info[i].t_c >= gScroll_Info[i].t_d) && gScroll_Info[i].flag)
			{
				text_scroll_Once(i);
				gScroll_Info[i].t_c = 0;
			}
		}
	}
}

/***********************************************************************************
* Function Name	: progress_bar
* Description	: Display progress_bar.
* Input			: - type: progress_bar info sources
				  - buff: progress_bar info
* Output        : None
* Return        : None
************************************************************************************/
void progress_bar(uint8_t type, uint8_t *buff)
{
	uint8_t buff1[12] = {0};
	int16_t sum = 0;
	uint16_t w, h;
	uint16_t dw1 = 0, dh1 = 0, bgw, bgh;
	uint16_t pointer, p_add, x2, y2, x1, y1, bar_id, bg_id;
	int16_t Vmax, Vmin;
	uint8_t dir;

	if (type == 0) // instruction information source is configuration file
	{
		p_add = (buff[5] + (buff[6] << 8));
		x2 = buff[7] + (buff[8] << 8);
		y2 = buff[9] + (buff[10] << 8);
		bar_id = buff[11] + (buff[12] << 8);
		dir = buff[13];
		Vmax = buff[14] + (buff[15] << 8);
		Vmin = buff[16] + (buff[17] << 8);
		x1 = buff[18] + (buff[19] << 8);
		y1 = buff[20] + (buff[21] << 8);
		bg_id = buff[22] + (buff[23] << 8);
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		p_add = (var[pointer + 1] + (var[pointer + 2] << 8));
		x2 = var[pointer + 3] + (var[pointer + 4] << 8);
		y2 = var[pointer + 5] + (var[pointer + 6] << 8);
		bar_id = var[pointer + 7] + (var[pointer + 8] << 8);
		dir = var[pointer + 9];
		Vmax = var[pointer + 10] + (var[pointer + 11] << 8);
		Vmin = var[pointer + 12] + (var[pointer + 13] << 8);
		x1 = var[pointer + 14] + (var[pointer + 15] << 8);
		y1 = var[pointer + 16] + (var[pointer + 17] << 8);
		bg_id = var[pointer + 18] + (var[pointer + 19] << 8);
	}
	
		Var_AddrRemapping(&p_add);

	if (Pop_up_flag == 1) // Popup offset
	{
		x1 += Pop_up_x;
		y1 += Pop_up_y;
		x2 += Pop_up_x;
		y2 += Pop_up_y;
	}

	if (bar_id == 0xFFFF)
		return;

	if (bg_id != 0xFFFF)
	{
		LT_ReadFlash_UI(buff1, addr_index[10] + 12 * bg_id + multi_language * 12 * addr_index[11], 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		bgw = buff1[4] + (buff1[5] << 8);
		bgh = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		// progress_bar background
		if (pic_flag == 1 || pic_flag == 2)
//			LT268_pic_to_buffer(0, 0, bgw, m_PngData,
//								x1, y1, LCD_XSIZE_TFT, FullScreen_addr,
//								bgw, bgh, FullScreen_flag);
			LT268_BG_to_buffer(0, 0, bgw, m_PngData,
								x1, y1, bgw, bgh);
		
		LT268_pic_to_buffer(0, 0, bgw, m_PngData,
							0, 0, bgw, pic_add,
							bgw, bgh, pic_flag);

		// progress_bar picture
		LT_ReadFlash_UI(buff1, addr_index[10] + 12 * bar_id + multi_language * 12 * addr_index[11], 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		dw1 = pic_w;
		dh1 = pic_h;
		x2 = x2 - x1;
		y2 = y2 - y1;
	}
	else
	{
		// progress_bar coordinate set 0
		x2 = 0;
		y2 = 0;

		// progress_bar picture
		LT_ReadFlash_UI(buff1, addr_index[10] + 12 * bar_id + multi_language * 12 * addr_index[11], 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		bgw = pic_w;
		bgh = pic_h;

		dw1 = pic_w;
		dh1 = pic_h;

//		LT268_pic_to_buffer(0, 0, bgw, m_PngData,
//							x1, y1, LCD_XSIZE_TFT, FullScreen_addr,
//							bgw, bgh, FullScreen_flag);
		LT268_BG_to_buffer(0, 0, bgw, m_PngData,
							x1, y1, bgw, bgh);
	}

	switch (dir)
	{
	case 0: // From left to right

		sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
		if (sum > Vmax)
			sum = Vmax;
		else if (sum < Vmin)
			sum = Vmin;

		w = dw1 * (sum - Vmin) / (Vmax - Vmin);

		LT268_pic_to_buffer(x2, y2, bgw, m_PngData,
							0, 0, dw1, pic_add,
							w, dh1, pic_flag);

		break;
	case 1: // From right to left

		sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
		if (sum > Vmax)
			sum = Vmax;
		else if (sum < Vmin)
			sum = Vmin;

		w = (dw1) * (sum - Vmin) / (Vmax - Vmin);

		LT268_pic_to_buffer(x2 + dw1 - w, y2, bgw, m_PngData,
							dw1 - w, 0, dw1, pic_add,
							w, dh1, pic_flag);

		break;
	case 2: // From top to bottom

		sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
		if (sum > Vmax)
			sum = Vmax;
		else if (sum < Vmin)
			sum = Vmin;

		h = dh1 * (sum - Vmin) / (Vmax - Vmin);

		LT268_pic_to_buffer(x2, y2, bgw, m_PngData,
							0, 0, dw1, pic_add,
							dw1, h, pic_flag);

		break;
	case 3: // From bottom to top

		sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
		if (sum > Vmax)
			sum = Vmax;
		else if (sum < Vmin)
			sum = Vmin;

		h = dh1 * (sum - Vmin) / (Vmax - Vmin);

		LT268_pic_to_buffer(x2, y2 + dh1 - h, bgw, m_PngData,
							0, dh1 - h, dw1, pic_add,
							dw1, h, pic_flag);
		break;
	default:
		break;
	}

	// display
	LT268_buffer_to_TFT(0, 0, bgw, m_PngData,
						x1, y1, bgw, bgh);
}

/***********************************************************************************
* Function Name	: Circular_progress_bar
* Description	: Display ring progress bar.
* Input         : - type: ring info sources
				  - buff: ring info
* Output        : None
* Return        : None
************************************************************************************/
void Circular_progress_bar(uint8_t type, uint8_t *buff)
{

	uint8_t I_num, D_num, Alig, zk_id, flag, n = 0, i = 0, kk = 0, flag1 = 0;
	uint8_t buff1[16],Symbol = 0;
	uint16_t temp, xd = 0;
	uint16_t pointer, p_add, x, y, dx, dy, fornt_id, bg_id, Sangle, Eangle;
	uint16_t S_id, E_id;
	int16_t Vmax, Vmin, angle,tt,value1;
	int32_t value, ll;
	uint16_t xR, yR;
	uint16_t num_w, dot_w, h, canvas_numw, canvas_dotw;
	uint32_t color, zk_addr;
	uint16_t ring_R, ring_CX, ring_CY; // ring radius,centre point
	int32_t hh;

	if (type == 0) // instruction information source is configuration file
	{
		p_add = (buff[5] + (buff[6] << 8));
		x = buff[7] + (buff[8] << 8);
		y = buff[9] + (buff[10] << 8);
		fornt_id = buff[11] + (buff[12] << 8);
		bg_id = buff[13] + (buff[14] << 8);
		Vmin = buff[15] + (buff[16] << 8);
		Vmax = buff[17] + (buff[18] << 8);
		Sangle = buff[19] + (buff[20] << 8);
		Eangle = buff[21] + (buff[22] << 8);
		dx = buff[23] + (buff[24] << 8);
		dy = buff[25] + (buff[26] << 8);
		I_num = buff[27];
		D_num = buff[28];
		Alig = buff[29];
		zk_id = buff[30];
		color = buff[31] + (buff[32] << 8) + (buff[33] << 16);
		S_id = buff[34] + (buff[35] << 8);
		E_id = buff[36] + (buff[37] << 8);
		flag = buff[38];
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		p_add = (var[pointer + 1] + (var[pointer + 2] << 8));
		x = var[pointer + 3] + (var[pointer + 4] << 8);
		y = var[pointer + 5] + (var[pointer + 6] << 8);
		fornt_id = var[pointer + 7] + (var[pointer + 8] << 8);
		bg_id = var[pointer + 9] + (var[pointer + 10] << 8);
		Vmin = var[pointer + 11] + (var[pointer + 12] << 8);
		Vmax = var[pointer + 13] + (var[pointer + 14] << 8);
		Sangle = var[pointer + 15] + (var[pointer + 16] << 8);
		Eangle = var[pointer + 17] + (var[pointer + 18] << 8);
		dx = var[pointer + 19] + (var[pointer + 20] << 8);
		dy = var[pointer + 21] + (var[pointer + 22] << 8);
		I_num = var[pointer + 23];
		D_num = var[pointer + 24];
		Alig = var[pointer + 25];
		zk_id = var[pointer + 26];
		color = var[pointer + 27] + (var[pointer + 28] << 8) + (var[pointer + 29] << 16);
		S_id = var[pointer + 30] + (var[pointer + 31] << 8);
		E_id = var[pointer + 32] + (var[pointer + 33] << 8);
		flag = var[pointer + 34];
	}

	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
		dx += Pop_up_x;
		dy += Pop_up_y;
	}

	// BG
	if (bg_id <= addr_index[11])
	{
		LT_ReadFlash_UI(buff1, addr_index[10] + 12 * bg_id + multi_language * 12 * addr_index[11], 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		if(pic_flag == ColorARGB0565 || pic_flag == ColorARGB4444 || pic_flag == ColorARGB8565)
		LT268_BG_to_buffer(0,0,pic_w,m_PngData,
				x, y,pic_w, pic_h);

		if (pic_len != 0 && pic_flag != 0xFF)
		{
			LT268_pic_to_buffer(0, 0, pic_w, m_PngData,
								0, 0, pic_w, pic_add,
								pic_w, pic_h, pic_flag);
		}

		LT_ReadFlash_UI(buff1, addr_index[10] + 12 * fornt_id + multi_language * 12 * addr_index[11], 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

	}
	else  //  BG == fullscreen
	{
		if(fornt_id <= addr_index[11])
		{
			LT_ReadFlash_UI(buff1, addr_index[10] + 12 * fornt_id + multi_language * 12 * addr_index[11], 12);
			pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
			pic_w = buff1[4] + (buff1[5] << 8);
			pic_h = buff1[6] + (buff1[7] << 8);
			pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
			pic_flag = buff1[11];

			if(pic_flag == ColorARGB0565 || pic_flag == ColorARGB4444 || pic_flag == ColorARGB8565)
				LT268_BG_to_buffer(0,0,pic_w,m_PngData,
						x, y,pic_w, pic_h);

		}
		else  return;
	}

	if (pic_w % 2)
	{
		ring_R = pic_w / 2 + 1;
		ring_CX = pic_w / 2;
		ring_CY = pic_w / 2;
	}
	else
	{
		ring_R = pic_w / 2;
		ring_CX = pic_w / 2 - 1;
		ring_CY = pic_w / 2 - 1;
	}

	tt = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
	
	if (tt <= Vmin)
		angle = Sangle;
	else if (tt >= Vmax)
		angle = Eangle;
	else
		angle = (Eangle - Sangle) * (tt - Vmin) / (Vmax - Vmin) + Sangle;
	//LTPrintf("angle %d  \r\n", angle);

	//���м����ȡ
	if((angle>0)&&(angle<=90))
	{
//		if(angle!=90)
			for (uint16_t yy = ring_CY; yy < pic_h; yy++)
			{
				hh=ring_CX-(yy-ring_CY)*FastTan(angle)/MAGNIFICATION;

//				if(hh<0)
//					break;
				LT_ReadFlash_DMA_UI(DMA_rxbuf1, pic_add+pic_w*yy*2, ring_R*2);
				for (uint16_t xx = 0; xx < ring_R; xx++)
				{
					if(xx>hh)
						LT268_buffer_pixel_blending(&p16_m_PngData[pic_w*yy + xx], &p16_DMA_rxbuf1[xx], pic_flag);
				}
			}
	}
	else if((angle>90)&&(angle<=180))
	{
		LT268_pic_to_buffer(0, ring_CY, pic_w, m_PngData,
				0, ring_CY, pic_w, pic_add,
				ring_R, pic_h-ring_CY, pic_flag);

		for (uint16_t yy = 0; yy < ring_R; yy++)
		{
			hh=ring_CX-(ring_CY-yy)*MAGNIFICATION/FastTan(angle-90);

				if(hh>ring_R)
					break;
			LT_ReadFlash_DMA_UI(DMA_rxbuf1, pic_add+pic_w*yy*2, ring_R*2);
			for (uint16_t xx = 0; xx < ring_R; xx++)
			{
				if(xx<hh)
					LT268_buffer_pixel_blending(&p16_m_PngData[pic_w*yy + xx], &p16_DMA_rxbuf1[xx], pic_flag);
			}
		}
	}
	else if((angle>180)&&(angle<=270))
	{
		LT268_pic_to_buffer(0, 0, pic_w, m_PngData,
				0, 0, pic_w, pic_add,
				ring_R, pic_h, pic_flag);

		for (uint16_t yy = 0; yy < ring_R; yy++)
		{
			hh=(ring_CY-yy)*FastTan(angle-180)/MAGNIFICATION;

//			if(hh>ring_R)
//				break;
			LT_ReadFlash_DMA_UI(DMA_rxbuf1, pic_add+pic_w*yy*2+ring_CX*2, ring_R*2);
			for (uint16_t xx = 0; xx < ring_R; xx++)
			{
				if(xx<hh)
					LT268_buffer_pixel_blending(&p16_m_PngData[pic_w*yy+ring_CX + xx], &p16_DMA_rxbuf1[xx], pic_flag);
			}
		}
	}
	else if((angle>270)&&(angle<=360))
	{
		LT268_pic_to_buffer(0, 0, pic_w, m_PngData,
				0, 0, pic_w, pic_add,
				pic_w, ring_R, pic_flag);
		LT268_pic_to_buffer(0, ring_CY, pic_w, m_PngData,
				0, ring_CY, pic_w, pic_add,
				ring_R, pic_h-ring_CY, pic_flag);

		for (uint16_t yy = ring_CY; yy < pic_h; yy++)
		{
			hh=(yy-ring_CY)*MAGNIFICATION/FastTan(angle-270);

//			if(hh>ring_R)
//				break;
			LT_ReadFlash_DMA_UI(DMA_rxbuf1, pic_add+pic_w*yy*2+(ring_CX+1)*2, ring_R*2);
			for (uint16_t xx = 0; xx < ring_R; xx++)
			{
				if(xx>=hh)
					LT268_buffer_pixel_blending(&p16_m_PngData[pic_w*yy+(ring_CX+1) + xx], &p16_DMA_rxbuf1[xx], pic_flag);
			}
		}
	 }


	if (flag == 1)
	{
		LT_ReadFlash_UI(buff1, addr_index[2] + zk_id * 8, 4);
		zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		value1 = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
		ll = pow(10, I_num + D_num);
		value = value1 % ll;
		if (value1 < 0)
        {
            Display_buff[Symbol] = '-';
            Symbol = 1;
            value = ~value1 + 1;
        }
		ll = value;
		do
		{ // Get the number of digits
			n++;
			ll /= 10;
		} while (ll > 0);
		if (D_num > 0) // With decimal point
		{
			if (D_num >= n)
			{
				Display_buff[Symbol] = '0';
				Display_buff[Symbol + 1] = '.';
				for (i = n; D_num > i; i++)
				{
					Display_buff[Symbol + 2 + i - n] = '0';
				}

				sprintf(&Display_buff[Symbol + 2 + D_num - n], "%d", value);


			}
			else
			{
				sprintf(&Display_buff[Symbol], "%d", value);

				for (i = 0; i < D_num; i++)
				{
					Display_buff[n + Symbol - i] = Display_buff[n - 1 + Symbol - i];
				}

				Display_buff[n + Symbol - D_num] = '.';

			}
		}
		else
		{
			sprintf(&Display_buff[Symbol], "%d", value);
		}

		LT_ReadFlash_UI(buff1, zk_addr, 4);

		LT_Print_zk_Font_BUFF(4, zk_addr,
							  LAY_BUFF1, LCD_XSIZE_TFT, buff1[2], buff1[3], Alig, color, Black, 0,
							  pic_w, pic_h, m_PngData, dx - x, dy - y,
							  0, 0, Display_buff, sizeof(Display_buff));
	}
	else if (flag == 2)
	{
		memset(Display_buff, 0, 20);
		value1 = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
		
		if (value1 < 0)
        {
            Display_buff[kk] = 11;
            kk++;
            value = ~value1 + 1;
        }
        else
        {
            value = value1;
        }
		value = value % ((int)powf(10, I_num + D_num));

		for (i = 0; i < I_num; i++) // Integer part
		{
			Display_buff[kk] = value / (int)powf(10, I_num - i - 1 + D_num);

			if (Display_buff[kk] != 0 || flag1 == 1)
			{
				kk++;
				flag1 = 1;
			}
			value = value % (int)powf(10, I_num - i - 1 + D_num);
		}
		if (D_num > 0)
		{
			if (flag1 == 0)
			{
				Display_buff[kk] = 0; //"."
				kk++;
			}
			Display_buff[kk] = 10; //"."
			kk++;
		}
		else if (flag1 == 0)
		{
			Display_buff[kk] = 0; //"."
			kk++;
		}

		for (i = 0; i < D_num; i++) // Fractional part
		{
			Display_buff[kk] = value / (int)powf(10, D_num - i - 1);
			kk++;
			value = value % (int)powf(10, i - 1 + D_num);
		}

		xd = 0;
		for (i = 0; i < kk; i++)
		{
            if (S_id + Display_buff[i] >= addr_index[11]) continue; // ICON is available
            LT_ReadFlash_UI(buff1, addr_index[10] + 12 * (S_id + Display_buff[i]) + multi_language * 12 * addr_index[11], 12);
            num_w = buff1[4] + (buff1[5] << 8);
            xd += num_w;
		}

		if (Alig == 0)
			dx = dx - x;
		else if (Alig == 1)
			dx = dx - x - xd / 2;
		else if (Alig == 2)
			dx = dx - x - xd + 1;

        for (i = 0; i < kk; i++)
        {
            if (S_id + Display_buff[i] >= addr_index[11])
                continue; // ICON is available
            LT_ReadFlash_UI(buff1, addr_index[10] + 12 * (S_id + Display_buff[i]) + multi_language * 12 * addr_index[11], 12);
            PICINFO[0].addr = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
            PICINFO[0].w = buff1[4] + (buff1[5] << 8);
            PICINFO[0].h = buff1[6] + (buff1[7] << 8);
            PICINFO[0].len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
            PICINFO[0].flag = buff1[11];
            LT268_pic_to_buffer(dx, dy - y, pic_w, m_PngData,
                                0, 0, PICINFO[0].w, PICINFO[0].addr,
                    PICINFO[0].w, PICINFO[0].h, PICINFO[0].flag);
            dx += PICINFO[0].w;
        }
	}

	LT268_buffer_to_TFT(0, 0, pic_w, m_PngData,
						x, y, pic_w, pic_h);


}


/***********************************************************************************
* Function Name	: Pointer_display
* Description	: Get Pointer_display info.
* Input			: - type: time counter info sources
				  - buff: time counter info
* Output		: None
* Return		: None
************************************************************************************/
Pointer_Info gPointer_Info[4];
uint8_t Pointer_Count_num = 0;
uint8_t Pointer_Count_flag = 0;
void Pointer_display(uint8_t type, uint8_t *buff)
{
	uint16_t pointer = 0;
	uint8_t buff1[16] = {0};
	uint16_t canvas_w;
	if (type == 0)
	{
		gPointer_Info[Pointer_Count_num].v_add = (buff[5] + (buff[6] << 8));
		gPointer_Info[Pointer_Count_num].base_id = buff[7] + (buff[8] << 8);;
		gPointer_Info[Pointer_Count_num].x = buff[9] + (buff[10] << 8);
		gPointer_Info[Pointer_Count_num].y = buff[11] + (buff[12] << 8);
		gPointer_Info[Pointer_Count_num].w = buff[13] + (buff[14] << 8);
		gPointer_Info[Pointer_Count_num].h = buff[15] + (buff[16] << 8);
		gPointer_Info[Pointer_Count_num].Pointer_x = buff[17] + (buff[18] << 8);
		gPointer_Info[Pointer_Count_num].Pointer_y = buff[19] + (buff[20] << 8);
		gPointer_Info[Pointer_Count_num].Sangle = buff[21] + (buff[22] << 8);
		gPointer_Info[Pointer_Count_num].Eangle = buff[23] + (buff[24] << 8);
		gPointer_Info[Pointer_Count_num].once_angle = buff[25] + (buff[26] << 8);
		gPointer_Info[Pointer_Count_num].effect = buff[27];
		gPointer_Info[Pointer_Count_num].center_id = buff[28] + (buff[29] << 8);
		gPointer_Info[Pointer_Count_num].Show_Number = buff[30];
		gPointer_Info[Pointer_Count_num].Num_add = buff[31] + (buff[32] << 8);
		gPointer_Info[Pointer_Count_num].Num_type = buff[33];
		gPointer_Info[Pointer_Count_num].Num_x = buff[34] + (buff[35] << 8);
		gPointer_Info[Pointer_Count_num].Num_y = buff[36] + (buff[37] << 8);
		gPointer_Info[Pointer_Count_num].Num_sid = buff[38] + (buff[39] << 8);
		gPointer_Info[Pointer_Count_num].Num_eid = buff[40] + (buff[41] << 8);
		gPointer_Info[Pointer_Count_num].Num_Alig = buff[42] & 0x7F;
		gPointer_Info[Pointer_Count_num].leading_zero = (buff[42] & 0x80) >> 7;
		gPointer_Info[Pointer_Count_num].Num_Nint = buff[43];
		gPointer_Info[Pointer_Count_num].Num_Dint = buff[44];
		gPointer_Info[Pointer_Count_num].mode = buff[45];
		gPointer_Info[Pointer_Count_num].Pointer_w = (buff[46] + (buff[47] << 8)) / 2;
		gPointer_Info[Pointer_Count_num].L1 = buff[48] + (buff[49] << 8);
		gPointer_Info[Pointer_Count_num].L1_colour = buff[50] + (buff[51] << 8) + (buff[52] << 16);
		gPointer_Info[Pointer_Count_num].L2 = buff[53] + (buff[54] << 8);
		gPointer_Info[Pointer_Count_num].L2_colour = buff[55] + (buff[56] << 8) + (buff[57] << 16);
		gPointer_Info[Pointer_Count_num].Pointer_sid = buff[58] + (buff[59] << 8);
		gPointer_Info[Pointer_Count_num].Pointer_eid = buff[60] + (buff[61] << 8);
		gPointer_Info[Pointer_Count_num].Pointer_id = buff[62] + (buff[63] << 8);
		
		Var_AddrRemapping(&gPointer_Info[Pointer_Count_num].v_add);
	}
	else if (type == 1)
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		gPointer_Info[Pointer_Count_num].v_add = (var[pointer + 1] + (var[pointer + 2] << 8));
		gPointer_Info[Pointer_Count_num].base_id = var[pointer + 3] + (var[pointer + 4] << 8);;
		gPointer_Info[Pointer_Count_num].x = var[pointer + 5] + (var[pointer + 6] << 8);
		gPointer_Info[Pointer_Count_num].y = var[pointer + 7] + (var[pointer + 8] << 8);
		gPointer_Info[Pointer_Count_num].w = var[pointer + 9] + (var[pointer + 10] << 8);
		gPointer_Info[Pointer_Count_num].h = var[pointer + 11] + (var[pointer + 12] << 8);
		gPointer_Info[Pointer_Count_num].Pointer_x = var[pointer + 13] + (var[pointer + 14] << 8);
		gPointer_Info[Pointer_Count_num].Pointer_y = var[pointer + 15] + (var[pointer + 16] << 8);
		gPointer_Info[Pointer_Count_num].Sangle = var[pointer + 17] + (var[pointer + 18] << 8);
		gPointer_Info[Pointer_Count_num].Eangle = var[pointer + 19] + (var[pointer + 20] << 8);
		gPointer_Info[Pointer_Count_num].once_angle = var[pointer + 21] + (var[pointer + 22] << 8);
		gPointer_Info[Pointer_Count_num].effect = var[pointer + 23];
		gPointer_Info[Pointer_Count_num].center_id = var[pointer + 24] + (var[pointer + 25] << 8);
		gPointer_Info[Pointer_Count_num].Show_Number = var[pointer + 26];
		gPointer_Info[Pointer_Count_num].Num_add = var[pointer + 27] + (var[pointer + 28] << 8);
		gPointer_Info[Pointer_Count_num].Num_type = var[pointer + 29];
		gPointer_Info[Pointer_Count_num].Num_x = var[pointer + 30] + (var[pointer + 31] << 8);
		gPointer_Info[Pointer_Count_num].Num_y = var[pointer + 32] + (var[pointer + 33] << 8);
		gPointer_Info[Pointer_Count_num].Num_sid = var[pointer + 34] + (var[pointer + 35] << 8);
		gPointer_Info[Pointer_Count_num].Num_eid = var[pointer + 36] + (var[pointer + 37] << 8);
		gPointer_Info[Pointer_Count_num].Num_Alig = var[pointer + 38] & 0x7F;
		gPointer_Info[Pointer_Count_num].leading_zero = (var[pointer + 38] & 0x80) >> 7;
		gPointer_Info[Pointer_Count_num].Num_Nint = var[pointer + 39];
		gPointer_Info[Pointer_Count_num].Num_Dint = var[pointer + 40];
		gPointer_Info[Pointer_Count_num].mode = var[pointer + 41];
		gPointer_Info[Pointer_Count_num].Pointer_w = (var[pointer + 42] + (var[pointer + 43] << 8)) / 2;
		gPointer_Info[Pointer_Count_num].L1 = var[pointer + 44] + (var[pointer + 45] << 8);
		gPointer_Info[Pointer_Count_num].L1_colour = var[pointer + 46] + (var[pointer + 47] << 8) + (var[pointer + 48] << 16);
		gPointer_Info[Pointer_Count_num].L2 = var[pointer + 49] + (var[pointer + 50] << 8);
		gPointer_Info[Pointer_Count_num].L2_colour = var[pointer + 51] + (var[pointer + 52] << 8) + (var[pointer + 53] << 16);
		gPointer_Info[Pointer_Count_num].Pointer_sid = var[pointer + 54] + (var[pointer + 55] << 8);
		gPointer_Info[Pointer_Count_num].Pointer_eid = var[pointer + 56] + (var[pointer + 57] << 8);
		gPointer_Info[Pointer_Count_num].Pointer_id = var[pointer + 58] + (var[pointer + 59] << 8);
		
		Var_AddrRemapping(&gPointer_Info[Pointer_Count_num].v_add);
	}
	
	gPointer_Info[Pointer_Count_num].current_angle = (var[gPointer_Info[Pointer_Count_num].v_add * 2] << 8) + var[gPointer_Info[Pointer_Count_num].v_add * 2 + 1];
	
	Run_Pointer(Pointer_Count_num);
	Pointer_Count_num++;

}

uint8_t Run_Pointer(uint8_t num)
{
	uint8_t n = 0, flag = 0, i = 0, kk = 0, Symbol = 0;
	uint8_t buff1[16] = {0};
	int16_t angle, temp_angle;
	uint16_t x_src = 0, y_src = 0, w_des, h_des, x_des, y_des,w_max,h_max;
	uint16_t num_w, dot_w, h, canvas_numw, canvas_dotw;
	uint16_t xd = 0, dx = 0;
	int16_t x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0, x4 = 0, y4 = 0;
	int16_t Pointer_x,Pointer_y;
	int32_t value = 0;
	int8_t value1 = 0;
	int16_t value2 = 0;
	uint16_t num_w0 = 0, num_h0 = 0;
	uint16_t num_width=0;
	uint16_t num_height=0;

	if (DioKb_flag == 1) // In the keyboard input interface
	{
		if (!(gPointer_Info[num].x > gDio_Info[Dio_num].Xe || (gPointer_Info[num].x + gPointer_Info[num].w) < gDio_Info[Dio_num].Xs || gPointer_Info[num].y > gDio_Info[Dio_num].Ye || (gPointer_Info[num].y + gPointer_Info[num].h) < gDio_Info[Dio_num].Ys))
		{
			return 0;
		}
	}
	else if (AioKb_flag == 1) // In the keyboard input interface
	{
		if (!(gPointer_Info[num].x > gAio_Info[Aio_num].Xe || (gPointer_Info[num].x + gPointer_Info[num].w) < gAio_Info[Aio_num].Xs || gPointer_Info[num].y > gAio_Info[Aio_num].Ye || (gPointer_Info[num].y + gPointer_Info[num].h) < gAio_Info[Aio_num].Ys))
		{
			return 0;
		}
	}
	else if (GBKioKb_flag == 1) // In the keyboard input interface
	{
		if (!(gPointer_Info[num].x > gGBKio_Info[GBKio_num].Xe || (gPointer_Info[num].x + gPointer_Info[num].w) < gGBKio_Info[GBKio_num].Xs || gPointer_Info[num].y > gGBKio_Info[GBKio_num].Ye || (gPointer_Info[num].y + gPointer_Info[num].h) < gGBKio_Info[GBKio_num].Ys))
		{
			return 0;
		}
	}


	if (gPointer_Info[num].mode != 5)
	{
		if (gPointer_Info[num].base_id != 0xFFFF)
		{
			LT_ReadFlash_UI(buff1, addr_index[10] + multi_language * 12 * addr_index[11] + 12 * gPointer_Info[num].base_id , 12);
			pic_add = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
			pic_w = buff1[4] + (buff1[5] << 8);
			pic_h = buff1[6] + (buff1[7] << 8);
			pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
			pic_flag = buff1[11];

			if (pic_len != 0 && pic_flag != 0xFF)
			{
				if(pic_flag == 1 || pic_flag ==2)
				LT_getBackGround(gPointer_Info[num].x,gPointer_Info[num].y,gPointer_Info[num].w, gPointer_Info[num].h, m_PngData, PIC_ON_BaseImg);		

				LT268_pic_to_buffer(0,0,gPointer_Info[num].w,m_PngData,
									0,0,pic_w,pic_add,
									pic_w,pic_h,pic_flag);

			}
		}
		else
		{
			LT_getBackGround(gPointer_Info[num].x,gPointer_Info[num].y,gPointer_Info[num].w, gPointer_Info[num].h, m_PngData, PIC_ON_BaseImg);		
		}
	}

	if (gPointer_Info[num].Show_Number == 1)
	{
		memset(Display_buff, 0, 20);
		if (gPointer_Info[num].Num_type == 0 )
		{
			value = var[gPointer_Info[num].Num_add * 2 + 1];
			var_temp[gPointer_Info[num].Num_add * 2 + 1] = var[gPointer_Info[num].Num_add * 2 + 1];
		}
		else if(gPointer_Info[num].Num_type == 0x80)
		{
			value1 = var[gPointer_Info[num].Num_add * 2 + 1];
			value = value1;
		}
		else if (gPointer_Info[num].Num_type == 1)
		{
			value = (var[gPointer_Info[num].Num_add * 2] << 8) + var[gPointer_Info[num].Num_add * 2 + 1];
			var_temp[gPointer_Info[num].Num_add * 2] = var[gPointer_Info[num].Num_add * 2];
			var_temp[gPointer_Info[num].Num_add * 2 + 1] = var[gPointer_Info[num].Num_add * 2 + 1];
		}
		else if (gPointer_Info[num].Num_type == 0x81)
		{
			value2 = (var[gPointer_Info[num].Num_add * 2] << 8) + var[gPointer_Info[num].Num_add * 2 + 1];
			var_temp[gPointer_Info[num].Num_add * 2] = var[gPointer_Info[num].Num_add * 2];
			var_temp[gPointer_Info[num].Num_add * 2 + 1] = var[gPointer_Info[num].Num_add * 2 + 1];
			value = value2;
		}
		else if (gPointer_Info[num].Num_type == 2 || gPointer_Info[num].Num_type == 0x82)
		{
			value = (var[gPointer_Info[num].Num_add * 2] << 24) + (var[gPointer_Info[num].Num_add * 2 + 1] << 16) + (var[gPointer_Info[num].Num_add * 2 + 2] << 8) + var[gPointer_Info[num].Num_add * 2 + 3];
			var_temp[gPointer_Info[num].Num_add * 2] = var[gPointer_Info[num].Num_add * 2];
			var_temp[gPointer_Info[num].Num_add * 2 + 1] = var[gPointer_Info[num].Num_add * 2 + 1];
			var_temp[gPointer_Info[num].Num_add * 2 + 2] = var[gPointer_Info[num].Num_add * 2 + 2];
			var_temp[gPointer_Info[num].Num_add * 2 + 3] = var[gPointer_Info[num].Num_add * 2 + 3];
		}

		if (value < 0)
		{
			Display_buff[kk] = 11;
			kk++;
			value = ~value + 1;
		}
		value = value % ((int)powf(10, gPointer_Info[num].Num_Nint + gPointer_Info[num].Num_Dint));
		for (i = 0; i < gPointer_Info[num].Num_Nint; i++) // All integers
		{
			Display_buff[kk] = value / (int)powf(10, gPointer_Info[num].Num_Nint - i - 1 + gPointer_Info[num].Num_Dint);
			if (gPointer_Info[num].leading_zero == 0)
			{
				if (Display_buff[kk] != 0 || flag == 1)
				{
					kk++;
					flag = 1; // The first digit is not 0
				}
			}
			else
			{
				kk++;
				flag = 1; // The first digit is not 0
			}
			value = value % (int)powf(10, gPointer_Info[num].Num_Nint - i - 1 + gPointer_Info[num].Num_Dint);
		}
		if (gPointer_Info[num].Num_Dint > 0)
		{
			if (flag == 0)
			{
				Display_buff[kk] = 0; //"."
				kk++;
			}
			Display_buff[kk] = 10; //"."
			kk++;
		}
		else
		{
			if (flag == 0)
			{
				Display_buff[kk] = 0; //"."
				kk++;
			}
		}
		for (i = 0; i < gPointer_Info[num].Num_Dint; i++) // Decimal
		{
			Display_buff[kk] = value / (int)powf(10, gPointer_Info[num].Num_Nint- i - 1);
			kk++;
			value = value % (int)powf(10, i - 1 + gPointer_Info[num].Num_Dint);
		}

		xd = 0;
		for (i = 0; i < kk; i++)
		{

			if (gPointer_Info[num].Num_sid + Display_buff[i] >= addr_index[11])
				continue;
			LT_ReadFlash_UI(buff1, addr_index[10] + multi_language * 12 * addr_index[11] + 12 * (gPointer_Info[num].Num_sid + Display_buff[i]), 12);
			pic_add = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
			num_w = buff1[4] + (buff1[5] << 8);
			h = buff1[6] + (buff1[7] << 8);
			pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
			pic_flag = buff1[11];
			if (i == 0)
			{
				num_w0 = num_w;
				num_h0 = h;
			}

			if (pic_len != 0 && pic_flag != 0xFF)
			{
				if (Screen_DIR == 0 || Screen_DIR == 2)
					xd += num_w;
				else if (Screen_DIR == 1 || Screen_DIR == 3)
					xd += h;
			}
		}

		if (gPointer_Info[num].mode != 5)
		{

			if (Screen_DIR == 0)
			{
				y_des = gPointer_Info[num].Num_y;// - gPointer_Info[num].y;
				if (gPointer_Info[num].Num_Alig == 0)		// Left alignment
					x_des = gPointer_Info[num].Num_x;// - gPointer_Info[num].x;
				else if (gPointer_Info[num].Num_Alig == 1)	// Mid alignment
					x_des = gPointer_Info[num].Num_x - xd / 2;// - gPointer_Info[num].x;
				else if (gPointer_Info[num].Num_Alig == 2)	// Right alignment
					x_des = gPointer_Info[num].Num_x - xd;// - gPointer_Info[num].x;
			}
			else if (Screen_DIR == 1)
			{
				x_des = gPointer_Info[num].Num_x - num_w;// - gPointer_Info[num].y;
				if (gPointer_Info[num].Num_Alig == 0)		// Left alignment
					y_des = gPointer_Info[num].Num_y;// - gPointer_Info[num].x;
				else if (gPointer_Info[num].Num_Alig == 1)	// Mid alignment
					y_des = gPointer_Info[num].Num_y - xd / 2;// - gPointer_Info[num].x;
				else if (gPointer_Info[num].Num_Alig == 2)	// Right alignment
					y_des = gPointer_Info[num].Num_y - xd;// - gPointer_Info[num].x;
			}
			else if (Screen_DIR == 2)
			{
				y_des = gPointer_Info[num].Num_y - h;// - gPointer_Info[num].y;
				if (gPointer_Info[num].Num_Alig == 0)		// Left alignment
					x_des = gPointer_Info[num].Num_x - num_w0;// - gPointer_Info[num].x;
				else if (gPointer_Info[num].Num_Alig == 1)	// Mid alignment
					x_des = gPointer_Info[num].Num_x - num_w0  + xd / 2 ;// - gPointer_Info[num].x;
				else if (gPointer_Info[num].Num_Alig == 2)	// Right alignment
					x_des = gPointer_Info[num].Num_x  + xd - num_w0;// - gPointer_Info[num].x;
			}
			else if (Screen_DIR == 3)
			{
				x_des = gPointer_Info[num].Num_x;// - gPointer_Info[num].y;
				if (gPointer_Info[num].Num_Alig == 0)		// Left alignment
					y_des = gPointer_Info[num].Num_y - num_h0;// - gPointer_Info[num].x;
				else if (gPointer_Info[num].Num_Alig == 1)	// Mid alignment
					y_des = gPointer_Info[num].Num_y + xd / 2 - num_h0;// - gPointer_Info[num].x;
				else if (gPointer_Info[num].Num_Alig == 2)	// Right alignment
					y_des = gPointer_Info[num].Num_y + xd - num_h0;// - gPointer_Info[num].x;
			}
			x_des -= gPointer_Info[num].x;
			y_des -= gPointer_Info[num].y;

			for (i = 0; i < kk; i++) // show
			{
				if (gPointer_Info[num].Num_sid + Display_buff[i] >= addr_index[11])
					continue;
				LT_ReadFlash_UI(buff1, addr_index[10] + 12 * (gPointer_Info[num].Num_sid + Display_buff[i]) + multi_language * 12 * addr_index[11], 12);
				pic_add = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
				num_w = buff1[4] + (buff1[5] << 8);
				h = buff1[6] + (buff1[7] << 8);
				pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
				pic_flag = buff1[11];

				if (pic_len != 0 && pic_flag != 0xFF)
				{

					LT268_pic_to_buffer(x_des,y_des,gPointer_Info[num].w,m_PngData,
										0,0,num_w,pic_add,
										num_w,h,pic_flag);

					if (Screen_DIR == 0)
						x_des += num_w;
					else if (Screen_DIR == 1)
						y_des += h;
					else if (Screen_DIR == 2)
						x_des -= num_w;
					else if (Screen_DIR == 3)
						y_des -= h;
					// x_des += num_w;
				}
			}
		}
		else
		{
			// if((gPointer_Info[Pointer_Count_num].flag==0)&&(x_des>gPointer_Info[num].pre_num_x))
			// {
			// 	LT_getBackGround(gPointer_Info[num].pre_num_x,gPointer_Info[num].pre_num_y,gPointer_Info[num].pre_num_w,gPointer_Info[num].pre_num_h, m_PngData, PIC_ON_BaseImg);
			// 	LT268_buffer_to_TFT(0,0,gPointer_Info[num].pre_num_w,m_PngData,gPointer_Info[num].pre_num_x,gPointer_Info[num].pre_num_y,gPointer_Info[num].pre_num_w,gPointer_Info[num].pre_num_h);
			// }

			if (gPointer_Info[num].pre_num_w > xd) // The previous data is wider than the current data, and more content needs to be cleared
			{
				if (Screen_DIR == 0)
				{
					w_max = gPointer_Info[num].pre_num_w;
					h_max = num_h0;
					y_src = gPointer_Info[num].Num_y;
					y_des = 0;
					if (gPointer_Info[num].Num_Alig == 0) // left
					{
						x_src = gPointer_Info[num].Num_x;
						x_des = 0;
					}
					else if (gPointer_Info[num].Num_Alig == 1) // center
					{
						x_src = gPointer_Info[num].Num_x - w_max / 2;
						x_des = (w_max - xd) / 2;
					}
					else if (gPointer_Info[num].Num_Alig == 2) // right
					{
						x_src = gPointer_Info[num].Num_x - w_max + 1;
						x_des = w_max - xd;
					}
				}
				else if (Screen_DIR == 1)
				{
					w_max = num_w0;
					h_max = gPointer_Info[num].pre_num_w;
					if (gPointer_Info[num].Num_Alig == 0) // left
					{
						x_src = gPointer_Info[num].Num_x - w_max;
						y_src = gPointer_Info[num].Num_y;
						x_des = 0;
						y_des = 0;
					}
					else if (gPointer_Info[num].Num_Alig == 1) // center
					{
						x_src = gPointer_Info[num].Num_x - w_max;
						y_src = gPointer_Info[num].Num_y - h_max / 2;;
						x_des = 0;
						y_des = (h_max - xd)/2;
					}
					else if (gPointer_Info[num].Num_Alig == 2) // right
					{
						x_src = gPointer_Info[num].Num_x - w_max;
						y_src = gPointer_Info[num].Num_y - h_max;;
						x_des = 0;
						y_des = h_max - xd;
					}
				}
				else if (Screen_DIR == 2)
				{
					w_max = gPointer_Info[num].pre_num_w;
					h_max = num_h0;
					if (gPointer_Info[num].Num_Alig == 0) // left
					{
						x_src = gPointer_Info[num].Num_x - w_max;
						y_src = gPointer_Info[num].Num_y - h_max;
						x_des = xd - num_w0 + h_max - xd;;
						y_des = 0;
					}
					else if (gPointer_Info[num].Num_Alig == 1) // center
					{
						x_src = gPointer_Info[num].Num_x - w_max/2;
						y_src = gPointer_Info[num].Num_y - h_max;
						x_des = xd - num_w0 + (w_max - xd)/2;
						y_des = 0;
					}
					else if (gPointer_Info[num].Num_Alig == 2) // right
					{
						x_src = gPointer_Info[num].Num_x ;
						y_src = gPointer_Info[num].Num_y - h_max;
						x_des = xd - num_w0;
						y_des = 0;
					}
				}
				else if (Screen_DIR == 3)
				{
					w_max = num_w0;
					h_max = gPointer_Info[num].pre_num_w;
					if (gPointer_Info[num].Num_Alig == 0) // left
					{
						x_src = gPointer_Info[num].Num_x;
						y_src = gPointer_Info[num].Num_y - h_max;
						x_des = 0;
						y_des = xd - num_h0 + h_max - xd;
					}
					else if (gPointer_Info[num].Num_Alig == 1) // center
					{
						x_src = gPointer_Info[num].Num_x;
						y_src = gPointer_Info[num].Num_y - h_max / 2;
						x_des = 0;
						y_des = xd - num_h0 + (h_max - xd)/2;
					}
					else if (gPointer_Info[num].Num_Alig == 2) // right
					{
						x_src = gPointer_Info[num].Num_x;
						y_src = gPointer_Info[num].Num_y;//- h_max;
						x_des = 0;
						y_des = xd - num_h0;
					}
				}
			}
			else
			{
				if (Screen_DIR == 0)
				{
					w_max = xd;
					h_max = num_h0;
					x_des = 0;
					y_src = gPointer_Info[num].Num_y;
					y_des = 0;
					if (gPointer_Info[num].Num_Alig == 0)
						x_src = gPointer_Info[num].Num_x;
					else if (gPointer_Info[num].Num_Alig == 1)
						x_src = gPointer_Info[num].Num_x - w_max / 2;
					else if (gPointer_Info[num].Num_Alig == 2)
						x_src = gPointer_Info[num].Num_x - w_max + 1;
				}
				else if (Screen_DIR == 1)
				{
					w_max = num_w0;
					h_max = xd;
					if (gPointer_Info[num].Num_Alig == 0) // left
					{
						x_src = gPointer_Info[num].Num_x - num_w0;
						y_src = gPointer_Info[num].Num_y - h_max;
						x_des = 0;
						y_des = 0;
					}
					else if (gPointer_Info[num].Num_Alig == 1) // center
					{
						x_src = gPointer_Info[num].Num_x - num_w0;
						y_src = gPointer_Info[num].Num_y - h_max / 2;
						x_des = 0;
						y_des = 0;
					}
					else if (gPointer_Info[num].Num_Alig == 2) // right
					{
						x_src = gPointer_Info[num].Num_x - num_w0;
						y_src = gPointer_Info[num].Num_y - h_max;
						x_des = 0;
						y_des = 0;
					}
				}
				else if (Screen_DIR == 2)
				{
					w_max = xd;
					h_max = num_h0;
					if (gPointer_Info[num].Num_Alig == 0) // left
					{
						x_src = gPointer_Info[num].Num_x - xd;
						y_src = gPointer_Info[num].Num_y - num_h0;
						x_des = xd - num_w0;
						y_des = 0;
					}
					else if (gPointer_Info[num].Num_Alig == 1) // center
					{
						x_src = gPointer_Info[num].Num_x - xd/2;
						y_src = gPointer_Info[num].Num_y - num_h0;
						x_des = xd - num_w0;
						y_des = 0;
					}
					else if (gPointer_Info[num].Num_Alig == 2) // right
					{
						x_src = gPointer_Info[num].Num_x ;
						y_src = gPointer_Info[num].Num_y - num_h0;
						x_des = xd - num_w0;
						y_des = 0;
					}
				}
				else if (Screen_DIR == 3)
				{
					w_max = num_w0;
					h_max = xd;
					if (gPointer_Info[num].Num_Alig == 0) // left
					{
						x_src = gPointer_Info[num].Num_x;
						y_src = gPointer_Info[num].Num_y - h_max;
						x_des = 0;
						y_des = xd - num_h0;
					}
					else if (gPointer_Info[num].Num_Alig == 1) // center
					{
						x_src = gPointer_Info[num].Num_x;
						y_src = gPointer_Info[num].Num_y - h_max / 2;
						x_des = 0;
						y_des = xd - num_h0;
					}
					else if (gPointer_Info[num].Num_Alig == 2) // right
					{
						x_src = gPointer_Info[num].Num_x;
						y_src = gPointer_Info[num].Num_y;//- h_max;
						x_des   = 0;
						y_des = xd - num_h0;
					}
				}


			}


			// num_width=0;
			// num_height=0;

			LT_getBackGround(x_src, y_src,w_max, h_max, m_PngData, PIC_ON_BaseImg);		
					 			
			for (i = 0; i < kk; i++) // show
			{
				if (gPointer_Info[num].Num_sid + Display_buff[i] >= addr_index[11])
					continue;
				LT_ReadFlash_UI(buff1, addr_index[10] + 12 * (gPointer_Info[num].Num_sid + Display_buff[i]) + multi_language * 12 * addr_index[11], 12);
				pic_add = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
				num_w = buff1[4] + (buff1[5] << 8);
				h = buff1[6] + (buff1[7] << 8);
				pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
				pic_flag = buff1[11];

				if(h>num_height)
					num_height = h;

				if (pic_len != 0 && pic_flag != 0xFF)
				{
					// LT_getBackGround(x_des+num_width,y_des,num_w,h, m_PngData, PIC_ON_BaseImg);
					// LT268_pic_to_buffer(0,0,num_w,m_PngData,0,0,num_w,pic_add,num_w,h,pic_flag);
					// LT268_buffer_to_TFT(0,0,num_w,m_PngData,x_des+num_width,y_des,num_w,h);
					// num_width += num_w;

					LT268_pic_to_buffer(x_des, y_des, w_max, m_PngData,
								0, 0, num_w, pic_add,
								num_w, h, pic_flag);

					if (Screen_DIR == 0)
						x_des += num_w;
					else if (Screen_DIR == 1)
						y_des += h;
					else if (Screen_DIR == 2)
						x_des -= num_w;
					else if (Screen_DIR == 3)
						y_des -= h;
				}
			}

			LT268_buffer_to_TFT(0, 0, w_max, m_PngData,
								x_src, y_src, w_max, h_max);

			// gPointer_Info[num].pre_num_x=x_des;
			// gPointer_Info[num].pre_num_y=y_des;
			 gPointer_Info[num].pre_num_w = xd;
			// gPointer_Info[num].pre_num_h=num_height;
		}
	}

	if (((var[gPointer_Info[num].v_add * 2] << 8) + var[gPointer_Info[num].v_add * 2 + 1]) > gPointer_Info[num].Eangle)
	{
		var[gPointer_Info[num].v_add * 2] = (gPointer_Info[num].Eangle >> 8) & 0xFF;
		var[gPointer_Info[num].v_add * 2 + 1] = gPointer_Info[num].Eangle & 0xFF;
	}
	else if (((var[gPointer_Info[num].v_add * 2] << 8) + var[gPointer_Info[num].v_add * 2 + 1]) < gPointer_Info[num].Sangle)
	{
		var[gPointer_Info[num].v_add * 2] = (gPointer_Info[num].Sangle >> 8) & 0xFF;
		var[gPointer_Info[num].v_add * 2 + 1] = gPointer_Info[num].Sangle & 0xFF;
	}
	if (gPointer_Info[num].effect == 1)
	{
		temp_angle = (var[gPointer_Info[num].v_add * 2] << 8) + var[gPointer_Info[num].v_add * 2 + 1];
		if (gPointer_Info[num].current_angle < temp_angle)
		{
			gPointer_Info[num].current_angle += gPointer_Info[num].once_angle;
			if(gPointer_Info[num].current_angle >= temp_angle)
			{
				gPointer_Info[num].current_angle = temp_angle;
				var_temp[gPointer_Info[num].v_add * 2] = var[gPointer_Info[num].v_add * 2];
				var_temp[gPointer_Info[num].v_add * 2 + 1] = var[gPointer_Info[num].v_add * 2 + 1];
			}
		}
		else if (gPointer_Info[num].current_angle > temp_angle)
		{
			gPointer_Info[num].current_angle -= gPointer_Info[num].once_angle;
			if(gPointer_Info[num].current_angle <= temp_angle)
			{
				gPointer_Info[num].current_angle = temp_angle;
				var_temp[gPointer_Info[num].v_add * 2] = var[gPointer_Info[num].v_add * 2];
				var_temp[gPointer_Info[num].v_add * 2 + 1] = var[gPointer_Info[num].v_add * 2 + 1];

			}
		}
		else if (gPointer_Info[num].current_angle == temp_angle)
		{
			var_temp[gPointer_Info[num].v_add * 2] = var[gPointer_Info[num].v_add * 2];
			var_temp[gPointer_Info[num].v_add * 2 + 1] = var[gPointer_Info[num].v_add * 2 + 1];
		}
	}
	else
	{
		gPointer_Info[num].current_angle = (var[gPointer_Info[num].v_add * 2] << 8) + var[gPointer_Info[num].v_add * 2 + 1];
		var_temp[gPointer_Info[num].v_add * 2] = var[gPointer_Info[num].v_add * 2];
		var_temp[gPointer_Info[num].v_add * 2 + 1] = var[gPointer_Info[num].v_add * 2 + 1];
	}

	if (gPointer_Info[num].mode == 0 || gPointer_Info[num].mode == 1)  // 2Ddrawing / 2Dsmooth
	{
		angle = gPointer_Info[num].current_angle;

		if (Screen_DIR == 0)
		{
			angle = gPointer_Info[num].current_angle;
		}
		else if (Screen_DIR == 1)
		{
			angle = gPointer_Info[num].current_angle + 90;
			angle = angle % 360;
		}
		else if (Screen_DIR == 2)
		{
			angle = gPointer_Info[num].current_angle + 180;
			angle = angle % 360;
		}
		if (Screen_DIR == 3)
		{
			angle = gPointer_Info[num].current_angle + 270;
			angle = angle % 360;
		}

		x1 = gPointer_Info[num].Pointer_x + gPointer_Info[num].Pointer_w * fast_sin(angle + 270)/MULTIPLE  - gPointer_Info[num].x;
		y1 = gPointer_Info[num].Pointer_y - gPointer_Info[num].Pointer_w * fast_cos(angle + 270)/MULTIPLE - gPointer_Info[num].y;

		x2 = gPointer_Info[num].Pointer_x + gPointer_Info[num].L2 * fast_sin(angle)/MULTIPLE  - gPointer_Info[num].x;
		y2 = gPointer_Info[num].Pointer_y - gPointer_Info[num].L2 * fast_cos(angle)/MULTIPLE - gPointer_Info[num].y;

		x3 = gPointer_Info[num].Pointer_x + gPointer_Info[num].Pointer_w * fast_sin(angle + 90)/MULTIPLE  - gPointer_Info[num].x;
		y3 = gPointer_Info[num].Pointer_y - gPointer_Info[num].Pointer_w * fast_cos(angle + 90)/MULTIPLE - gPointer_Info[num].y;

		x4 = gPointer_Info[num].Pointer_x + gPointer_Info[num].L1 * fast_sin(angle + 180)/MULTIPLE  - gPointer_Info[num].x;
		y4 = gPointer_Info[num].Pointer_y - gPointer_Info[num].L1 * fast_cos(angle + 180)/MULTIPLE - gPointer_Info[num].y;

		LT268_DrawTriangle_Fill_Buffer(x1, y1, x2, y2, x4, y4, gPointer_Info[num].L2_colour,gPointer_Info[num].w);
		LT268_DrawTriangle_Fill_Buffer(x3, y3, x2, y2, x4, y4, gPointer_Info[num].L1_colour,gPointer_Info[num].w);

		if (gPointer_Info[num].mode == 1)
		{
			lineSDFAABB_BUFF(x1,y1,x2,y2,1,gPointer_Info[num].L2_colour,gPointer_Info[num].w);
			lineSDFAABB_BUFF(x1,y1,x4,y4,1,gPointer_Info[num].L2_colour,gPointer_Info[num].w);
			lineSDFAABB_BUFF(x2,y2,x3,y3,1,gPointer_Info[num].L1_colour,gPointer_Info[num].w);
			lineSDFAABB_BUFF(x3,y3,x4,y4,1,gPointer_Info[num].L1_colour,gPointer_Info[num].w);
		}

	}
	else if (gPointer_Info[num].mode == 2) // PNGdrawing
	{
		// none
	}
	else if (gPointer_Info[num].mode == 3)  // Animation
	{
		temp_angle = (gPointer_Info[num].current_angle - gPointer_Info[num].Sangle) / gPointer_Info[num].once_angle;

		LT_ReadFlash_UI(buff1, addr_index[10] + multi_language * 12 * addr_index[11] + 12 * (gPointer_Info[num].Pointer_sid + temp_angle), 12);
		pic_add = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		LT_ReadFlash_UI(buff1, pic_add, 4);
		Pointer_x = buff1[0] + (buff1[1] << 8);
		Pointer_y = buff1[2] + (buff1[3] << 8);

		if (pic_len != 0 && pic_flag != 0xFF)
		{
//			printf("pic_flag %d   x%x  \r\n",pic_flag,pic_add + 4);
//			if (pic_flag  == 2)
			{
				LT268_pic_to_buffer(gPointer_Info[num].Pointer_x - gPointer_Info[num].L1 + Pointer_x - gPointer_Info[num].x,
									gPointer_Info[num].Pointer_y - gPointer_Info[num].L1 + Pointer_y - gPointer_Info[num].y,
									gPointer_Info[num].w,m_PngData,
									0,0,pic_w,pic_add + 4,
									pic_w,pic_h,pic_flag);
			}
		}
	}
	else if (gPointer_Info[num].mode == 4) // Line
	{
		if (Screen_DIR == 0)
		{
			angle = gPointer_Info[num].current_angle;
		}
		else if (Screen_DIR == 1)
		{
			angle = gPointer_Info[num].current_angle + 90;
			angle = angle % 360;
		}
		else if (Screen_DIR == 2)
		{
			angle = gPointer_Info[num].current_angle + 180;
			angle = angle % 360;
		}
		if (Screen_DIR == 3)
		{
			angle = gPointer_Info[num].current_angle + 270;
			angle = angle % 360;
		}

		x1 = gPointer_Info[num].Pointer_x + gPointer_Info[num].L2 * fast_sin(angle)/MULTIPLE  - gPointer_Info[num].x;
		x2 = gPointer_Info[num].Pointer_x - gPointer_Info[num].L1 * fast_sin(angle)/MULTIPLE  - gPointer_Info[num].x;
		y1 = gPointer_Info[num].Pointer_y - gPointer_Info[num].L2 * fast_cos(angle)/MULTIPLE - gPointer_Info[num].y;
		y2 = gPointer_Info[num].Pointer_y + gPointer_Info[num].L1 * fast_cos(angle)/MULTIPLE - gPointer_Info[num].y;

		lineSDFAABB_BUFF(x1,y1,x2,y2,gPointer_Info[num].Pointer_w,gPointer_Info[num].L1_colour,gPointer_Info[num].w);
	}
	else if (gPointer_Info[num].mode == 5) // Icon
	{
		uint8_t overlap = 0;
		uint16_t x=0,y=0;
		uint16_t xOffset=0,yOffset=0;
		uint16_t width=0,height=0;
		temp_angle = (gPointer_Info[num].current_angle - gPointer_Info[num].Sangle) / gPointer_Info[num].once_angle;
		LT_ReadFlash_UI(buff1, addr_index[10] + multi_language * 12 * addr_index[11] + 12 * (gPointer_Info[num].Pointer_sid + temp_angle), 12);
		pic_add = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		LT_ReadFlash_UI(buff1, pic_add, 4);
		Pointer_x = buff1[0] + (buff1[1] << 8);
		Pointer_y = buff1[2] + (buff1[3] << 8);
		Pointer_x+=gPointer_Info[num].Pointer_x - gPointer_Info[num].L1;
		Pointer_y+=gPointer_Info[num].Pointer_y - gPointer_Info[num].L1;

		if (pic_len != 0 && pic_flag != 0xFF)
		{
			if(temp_angle!=gPointer_Info[num].pre_angle)
			{
				x=gPointer_Info[num].pre_pointer_x;
				y=gPointer_Info[num].pre_pointer_y;
				if(gPointer_Info[num].flag==0)
				{
					if((Pointer_x>gPointer_Info[num].pre_pointer_x)&&(Pointer_x<(gPointer_Info[num].pre_pointer_x+gPointer_Info[num].pre_pointer_w))&&\
						(Pointer_y>gPointer_Info[num].pre_pointer_y)&&(Pointer_y<(gPointer_Info[num].pre_pointer_y+gPointer_Info[num].pre_pointer_h)))
						{
							overlap=1;//�Ƕ�����
							xOffset=Pointer_x-gPointer_Info[num].pre_pointer_x;
							yOffset=Pointer_y-gPointer_Info[num].pre_pointer_y;
							width=pic_w+xOffset;
							height=pic_h+yOffset;
						}
					else if((Pointer_x<gPointer_Info[num].pre_pointer_x)&&(Pointer_x+pic_w>gPointer_Info[num].pre_pointer_x)&&\
							(Pointer_y<gPointer_Info[num].pre_pointer_y)&&(Pointer_y+pic_h>gPointer_Info[num].pre_pointer_y))
						{
							overlap=2;//�Ƕȱ�С
							x=Pointer_x;
							y=Pointer_y;
							xOffset=gPointer_Info[num].pre_pointer_x-Pointer_x;
							yOffset=gPointer_Info[num].pre_pointer_y-Pointer_y;
							width=gPointer_Info[num].pre_pointer_w+xOffset;
							height=gPointer_Info[num].pre_pointer_h+yOffset;
						}
					else
					{
						overlap=0;
						xOffset=0;
						yOffset=0;
						width=gPointer_Info[num].pre_pointer_w;
						height=gPointer_Info[num].pre_pointer_h;
					}
					LT_getBackGround(x,y,width,height, m_PngData, PIC_ON_BaseImg);
					if(!overlap)
						LT268_buffer_to_TFT(0,0,width,m_PngData,x,y,width,height);
				}
			}
			if((overlap==0)||(overlap==2))
			{
				xOffset=0;
				yOffset=0;
				if(overlap==0)
				{
					x=Pointer_x;
					y=Pointer_y;
					width=pic_w;
					height=pic_h;
					LT_getBackGround(x,y,width,height, m_PngData, PIC_ON_BaseImg);
				}
			}
			LT268_pic_to_buffer(xOffset,yOffset,width,m_PngData,0,0,pic_w,pic_add + 4,pic_w,pic_h,pic_flag);
			LT268_buffer_to_TFT(0,0,width,m_PngData,x,y,width,height);

			gPointer_Info[num].pre_angle=temp_angle;
			gPointer_Info[num].pre_pointer_x=Pointer_x;
			gPointer_Info[num].pre_pointer_y=Pointer_y;
			gPointer_Info[num].pre_pointer_w=pic_w;
			gPointer_Info[num].pre_pointer_h=pic_h;
		}
	}

	if (gPointer_Info[num].center_id != 0xFFFF )
	{
		LT_ReadFlash_UI(buff1, addr_index[10] + multi_language * 12 * addr_index[11] + 12 * gPointer_Info[num].center_id , 12);
		pic_add = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];


		if (pic_len != 0 && pic_flag != 0xFF)
		{
			LT268_pic_to_buffer(gPointer_Info[num].Pointer_x - pic_w/2 - gPointer_Info[num].x,
								gPointer_Info[num].Pointer_y - pic_h/2 - gPointer_Info[num].y,
								gPointer_Info[num].w,m_PngData,
								0,0,pic_w,pic_add,
								pic_w,pic_h,pic_flag);
		}
	}

	if (gPointer_Info[num].mode != 5)
	{
		LT268_buffer_to_TFT(0,0,gPointer_Info[num].w,m_PngData,gPointer_Info[num].x,gPointer_Info[num].y,gPointer_Info[num].w,gPointer_Info[num].h);
	}

	gPointer_Info[num].flag=0;
}

void Check_Pointer(void)
{
	if (Pointer_Count_num > 0 && Pointer_Count_flag == 1)
	{
		Pointer_Count_flag = 0;
		for (uint8_t i = 0; i < Pointer_Count_num; i++)
		{
			if (var[gPointer_Info[i].v_add * 2] != var_temp[gPointer_Info[i].v_add * 2] ||
				var[gPointer_Info[i].v_add * 2 + 1] != var_temp[gPointer_Info[i].v_add * 2 + 1] ||
				gPointer_Info[i].current_angle != ((var[gPointer_Info[i].v_add * 2] << 8) + var[gPointer_Info[i].v_add * 2 + 1]))
			{
				Run_Pointer(i); 
			}
			else if (gPointer_Info[i].Show_Number == 1)
			{
				if ((gPointer_Info[i].Num_type == 0 || gPointer_Info[i].Num_type == 0x80) &&
					var[gPointer_Info[i].Num_add * 2 + 1] != var_temp[gPointer_Info[i].Num_add * 2 + 1])
				{
					Run_Pointer(i); 
				}
				else if ((gPointer_Info[i].Num_type == 1 || gPointer_Info[i].Num_type == 0x81) &&
					(var[gPointer_Info[i].Num_add * 2] != var_temp[gPointer_Info[i].Num_add * 2] ||
					var[gPointer_Info[i].Num_add * 2 + 1] != var_temp[gPointer_Info[i].Num_add * 2 + 1]))
				{
					Run_Pointer(i); 
				}
				else if ((gPointer_Info[i].Num_type == 2 || gPointer_Info[i].Num_type == 0x82) &&
					(var[gPointer_Info[i].Num_add * 2] != var_temp[gPointer_Info[i].Num_add * 2] ||
					var[gPointer_Info[i].Num_add * 2 + 1] != var_temp[gPointer_Info[i].Num_add * 2 + 1]||
					var[gPointer_Info[i].Num_add * 2 + 2] != var_temp[gPointer_Info[i].Num_add * 2 + 2]||
					var[gPointer_Info[i].Num_add * 2 + 3] != var_temp[gPointer_Info[i].Num_add * 2 + 3]))
				{
					Run_Pointer(i); 
				}
			}
			
		}
	}
}



uint8_t curve_num = 0;		 // Number of curve controls
uint8_t curve_flag = 0;		 // Curve timing refresh flag bit
uint8_t curve_group_sum = 1; // Total number of groups in curve area
/***********************************************************************************
 * Function Name : Real_time_curve_display_static
 * Description   : Show static curves.
 * Input         : - curve: curve info
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Real_time_curve_display_static(Curve_Info curve)
{
    uint16_t points = 0, num = 0, yCentral = 0, x, y;
    int16_t X0 = 0, X1 = 0, Y0 = 0, Y1 = 0;
    uint16_t buff_w = curve.xe - curve.xs, buff_h = curve.ye - curve.ys;


    if (curve.dir == 0)
    {
        x = curve.xe - (curve.Width - 1);
        points = (x - curve.xs + 1) / curve.Dis_HOR;
    }
    else
    {
        x = curve.xs;
        points = (curve.xe - x + 1) / curve.Dis_HOR;
    }
    yCentral = (curve.ys + curve.Y_Central) + curve.VD_Central * curve.MUL_Y / 256;
    num = Curve_count[curve.channel] - 1 + 1024;

    // full-screen background
//    LT268_pic_to_buffer(0, 0, buff_w, m_PngData,
//                        curve.xs, curve.ys, LCD_XSIZE_TFT, FullScreen_addr,
//                        buff_w, buff_h, FullScreen_flag);
    LT268_BG_to_buffer(0, 0, buff_w, m_PngData,
                        curve.xs, curve.ys, buff_w, buff_h);
	
    for (uint16_t i = 0; i < points; i++)
    {

        X0 = x;
        if (curve.dir == 0)
        {
            X1 = x - curve.Dis_HOR;
            if (X1 < curve.xs)
                break;
        }
        else
        {
            X1 = x + curve.Dis_HOR;
            if (X1 + (curve.Width - 1) > curve.xe)
                break;
        }

        Y0 = yCentral - Curve_buff[curve.channel][num % 1024] * curve.MUL_Y / 256;
        Y1 = yCentral - Curve_buff[curve.channel][(num - 1) % 1024] * curve.MUL_Y / 256;

        if (Y0 < curve.ys)
            Y0 = curve.ys; // When the Y coordinate exceeds the upper or lower limit, it defaults to the upper or lower limit coordinate value
        else if (Y0 > curve.ye - curve.Width + 1)
            Y0 = curve.ye - curve.Width + 1; // Keep the part with lineweight greater than 1, so the Y coordinate value should be offset (lineweight - 1) pixels
        if (Y1 < curve.ys)
            Y1 = curve.ys;
        else if (Y1 > curve.ye - curve.Width + 1)
            Y1 = curve.ye - curve.Width + 1;
//        LT768_DrawLine_Width(X0, Y0, X1, Y1, curve.color, curve.Width);
        LT268_TFT_DrawLine_Width_Buffer(
                    X0 - curve.xs, Y0 - curve.ys,
                X1 - curve.xs, Y1 - curve.ys,
                curve.color, curve.Width, buff_w);

        if (curve.dir == 0)
            x = x - curve.Dis_HOR;
        else
            x = x + curve.Dis_HOR;

        num--;
    }

    // display
    LT268_buffer_to_TFT(0, 0, buff_w, m_PngData,
                        curve.xs, curve.ys, buff_w, buff_h);

}

/***********************************************************************************
 * Function Name : Real_time_curve_display_dynamic
 * Description   : Show Dynamic Curves.
 * Input         : - group: which group of curve
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Real_time_curve_display_dynamic(uint8_t group)
{
    uint8_t temp = 0, once_flag = 0;
    uint16_t points = 0, num = 0, yCentral = 0, x, y, i = 0, j = 0;
    int16_t X0 = 0, X1 = 0, Y0 = 0, Y1 = 0;
    uint16_t buff_w = 0, buff_h = 0;
	
    for (i = 0; i < curve_num; i++)
    {
        if (gCurve_Info[i].group == group)
        {
            // Only load the background once under the same group
            if (once_flag == 0)
            {
                buff_w = gCurve_Info[i].xe - gCurve_Info[i].xs + 1;
                buff_h = gCurve_Info[i].ye - gCurve_Info[i].ys + 1;

                // full_screen background
//                LT268_pic_to_buffer(0, 0, buff_w, m_PngData,
//                                    gCurve_Info[i].xs, gCurve_Info[i].ys, LCD_XSIZE_TFT, FullScreen_addr,
//                                    buff_w, buff_h, FullScreen_flag);
                LT268_BG_to_buffer(0, 0, buff_w, m_PngData,
                                    gCurve_Info[i].xs, gCurve_Info[i].ys, buff_w, buff_h);
				
                temp = i;
                once_flag = 1;
            }

            if (gCurve_Info[i].dir == 0)
            {
                x = gCurve_Info[i].xe - (gCurve_Info[i].Width - 1);
                points = (x - gCurve_Info[i].xs + 1) / gCurve_Info[i].Dis_HOR;
            }
            else
            {
                x = gCurve_Info[i].xs;
                points = (gCurve_Info[i].xe - x + 1) / gCurve_Info[i].Dis_HOR;
            }
            yCentral = (gCurve_Info[i].ys + gCurve_Info[i].Y_Central) + gCurve_Info[i].VD_Central * gCurve_Info[i].MUL_Y / 256;
            num = Curve_count[gCurve_Info[i].channel] - 1 + 1024;

            for (j = 0; j < points; j++)
            {
                X0 = x;
                if (gCurve_Info[i].dir == 0)
                {
                    X1 = x - gCurve_Info[i].Dis_HOR;
                    if (X1 < gCurve_Info[i].xs)
                        break;
                }
                else
                {
                    X1 = x + gCurve_Info[i].Dis_HOR;
                    if (X1 + (gCurve_Info[i].Width - 1) > gCurve_Info[i].xe)
                        break;
                }
                Y0 = yCentral - Curve_buff[gCurve_Info[i].channel][num % 1024] * gCurve_Info[i].MUL_Y / 256;
                Y1 = yCentral - Curve_buff[gCurve_Info[i].channel][(num - 1) % 1024] * gCurve_Info[i].MUL_Y / 256;

                if (Y0 < gCurve_Info[i].ys)
                    Y0 = gCurve_Info[i].ys;
                else if (Y0 > gCurve_Info[i].ye - gCurve_Info[i].Width + 1)
                    Y0 = gCurve_Info[i].ye - gCurve_Info[i].Width + 1;
                if (Y1 < gCurve_Info[i].ys)
                    Y1 = gCurve_Info[i].ys;
                else if (Y1 > gCurve_Info[i].ye - gCurve_Info[i].Width + 1)
                    Y1 = gCurve_Info[i].ye - gCurve_Info[i].Width + 1;

//                LT768_DrawLine_Width(X0, Y0, X1, Y1, gCurve_Info[i].color, gCurve_Info[i].Width);
                LT268_TFT_DrawLine_Width_Buffer(
                            X0 - gCurve_Info[i].xs, Y0 - gCurve_Info[i].ys,
                        X1 - gCurve_Info[i].xs, Y1 - gCurve_Info[i].ys,
                        gCurve_Info[i].color, gCurve_Info[i].Width, buff_w);

                if (gCurve_Info[i].dir == 0)
                    x = x - gCurve_Info[i].Dis_HOR;
                else
                    x = x + gCurve_Info[i].Dis_HOR;
                num--;
            }
        }
    }

    // display
    LT268_buffer_to_TFT(0, 0, buff_w, m_PngData,
                        gCurve_Info[temp].xs, gCurve_Info[temp].ys, buff_w, buff_h);
}

/***********************************************************************************
* Function Name	: Curve_display
* Description	: Get curves info.
* Input         : - type: curves info sources
                  - buff: curves info
* Output        : None
* Return        : None
************************************************************************************/
void Curve_display(uint8_t type, uint8_t *buff)
{
    uint8_t channel = 0, Dis_HOR = 0, Width = 0, i = 0, count = 0, dir = 0;
    uint16_t p_add, p_len, pointer;
    uint16_t xs = 0, ys = 0, xe = 0, ye = 0, Y_Central = 0, VD_Central = 0, MUL_Y = 0;
    uint32_t color = 0;

    if (type == 0)		// Instruction information source is configuration file
    {
        xs = buff[5] + (buff[6] << 8);
        ys = buff[7] + (buff[8] << 8);
        xe = buff[9] + (buff[10] << 8);
        ye = buff[11] + (buff[12] << 8);
        Y_Central = buff[13] + (buff[14] << 8);
        VD_Central = buff[15] + (buff[16] << 8);
        MUL_Y = buff[17] + (buff[18] << 8);
        color = buff[19] + (buff[20] << 8) + (buff[21] << 16);
        channel = buff[22] & 0x7F;
        dir = (buff[22] & 0x80) >> 7;
        Dis_HOR = buff[23];
        Width = buff[24];
    }
    else if (type == 1) // Instruction information ource is variable space
    {
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		xs = var[pointer + 1] + (var[pointer + 2] << 8);
		ys = var[pointer + 3] + (var[pointer + 4] << 8);
		xe = var[pointer + 5] + (var[pointer + 6] << 8);
		ye = var[pointer + 7] + (var[pointer + 8] << 8);
		Y_Central = var[pointer + 9] + (var[pointer + 10] << 8);
		VD_Central = var[pointer + 11] + (var[pointer + 12] << 8);
		MUL_Y = var[pointer + 13] + (var[pointer + 14] << 8);
		color = var[pointer + 15] + (var[pointer + 16] << 8) + (var[pointer + 17] << 16);
		channel = var[pointer + 18] & 0x7F;
		dir = (var[pointer + 18] & 0x80) >> 7;
		Dis_HOR = var[pointer + 19];
		Width = var[pointer + 20];
    }

    if (Pop_up_flag == 1) // Popup offset
    {
        xs += Pop_up_x;
        ys += Pop_up_y;
        xe += Pop_up_x;
        ye += Pop_up_y;
    }
    gCurve_Info[curve_num].xs = xs;
    gCurve_Info[curve_num].ys = ys;
    gCurve_Info[curve_num].xe = xe;
    gCurve_Info[curve_num].ye = ye;
    gCurve_Info[curve_num].Y_Central = Y_Central;
    gCurve_Info[curve_num].VD_Central = VD_Central;
    gCurve_Info[curve_num].MUL_Y = MUL_Y;
    gCurve_Info[curve_num].color = color;
    gCurve_Info[curve_num].channel = channel;
    gCurve_Info[curve_num].Dis_HOR = Dis_HOR;
    gCurve_Info[curve_num].Width = Width;
    gCurve_Info[curve_num].dir = dir;

    Real_time_curve_display_static(gCurve_Info[curve_num]);
	
    curve_update_flag[gCurve_Info[curve_num].channel] = 0;

    // Curve grouping
    if (curve_num)
    {
        for (i = 0; i < curve_num; i++)
        {
            if (gCurve_Info[curve_num].xs != gCurve_Info[i].xs ||
                gCurve_Info[curve_num].ys != gCurve_Info[i].ys ||
                gCurve_Info[curve_num].xe != gCurve_Info[i].xe ||
                gCurve_Info[curve_num].ye != gCurve_Info[i].ye)
            {
            // If x y w h is different, add a group of areas
                count++;
            }
            else
            {
                // If x y w h is the same, it will be classified into the same group of areas
                gCurve_Info[curve_num].group = gCurve_Info[i].group;
                break;
            }
        }
        if (count == curve_num) // Indicates that the latest control is compared with all previous controls. If the area is different, a new group of areas will be added
        {
            curve_group_sum++;
            gCurve_Info[curve_num].group = curve_group_sum;
        }
    }
    else // The first curve control defaults to group 0
    {
        curve_group_sum = 1;
        gCurve_Info[curve_num].group = curve_group_sum;
    }
    curve_num++;
}

void Display_Curve(void)
{
    uint8_t i = 0, j = 0;
    if (curve_num && curve_flag)
    {
        curve_flag = 0;
        for (i = 1; i <= curve_group_sum; i++)
        {
            for (j = 0; j < curve_num; j++)
            {
                // When a channel data is updated, multiple controls in the same group will be updated accordingly
                if (curve_update_flag[gCurve_Info[j].channel] && gCurve_Info[j].group == i)
                {
                    Real_time_curve_display_dynamic(i);
                    break;
                }
            }
        }
        for (i = 0; i < CURVE_SIZE; i++) // After all the curves are updated, clear the flag
        {
            curve_update_flag[i] = 0;
        }
    }
}


Count_Info gCount_Info[COUNT_SIZE];
Record_count_Info gRecord_count_Info[20];
uint8_t Count_sum = 0;
uint8_t Count_flag = 0;
uint8_t Record_count = 0;
uint16_t Count_reg[8];
uint8_t Count_reg_num;

/***********************************************************************************
* Function Name	: count_display
* Description	: Get time counter info.
* Input         : - type: time counter info sources
				  - buff: time counter info
* Output        : None
* Return        : None
************************************************************************************/
void count_display(uint8_t type, uint8_t *buff)
{
	uint8_t i = 0;
	uint16_t pointer = 0;
	
	if (type == 0)
	{
		gCount_Info[Count_sum].v_add = (buff[5] + (buff[6] << 8));
		gCount_Info[Count_sum].t_add = buff[7] + (buff[8] << 8);
		gCount_Info[Count_sum].c_add = buff[9] + (buff[10] << 8);
		gCount_Info[Count_sum].x = buff[11] + (buff[12] << 8);
		gCount_Info[Count_sum].y = buff[13] + (buff[14] << 8);
		gCount_Info[Count_sum].ID_start = buff[15] + (buff[16] << 8);
		gCount_Info[Count_sum].dis_mode = buff[17];
		gCount_Info[Count_sum].dir = buff[18];
		gCount_Info[Count_sum].end_mode = buff[19];
		gCount_Info[Count_sum].end_feedback = buff[20];
		gCount_Info[Count_sum].var_addr[0] = buff[21] + (buff[22] << 8);
		gCount_Info[Count_sum].var[0] = buff[23] + (buff[24] << 8);
		gCount_Info[Count_sum].var_addr[1] = buff[25] + (buff[26] << 8);
		gCount_Info[Count_sum].var[1] = buff[27] + (buff[28] << 8);
		gCount_Info[Count_sum].var_addr[2] = buff[29] + (buff[30] << 8);
		gCount_Info[Count_sum].var[2] = buff[31] + (buff[32] << 8);
		gCount_Info[Count_sum].var_addr[3] = buff[33] + (buff[34] << 8);
		gCount_Info[Count_sum].var[3] = buff[35] + (buff[36] << 8);
		gCount_Info[Count_sum].var_addr[4] = buff[37] + (buff[38] << 8);
		gCount_Info[Count_sum].var[4] = buff[39] + (buff[40] << 8);
		gCount_Info[Count_sum].var_addr[5] = buff[41] + (buff[42] << 8);
		gCount_Info[Count_sum].var[5] = buff[43] + (buff[44] << 8);
		gCount_Info[Count_sum].var_addr[6] = buff[45] + (buff[46] << 8);
		gCount_Info[Count_sum].var[6] = buff[47] + (buff[48] << 8);
		gCount_Info[Count_sum].var_addr[7] = buff[49] + (buff[50] << 8);
		gCount_Info[Count_sum].var[7] = buff[51] + (buff[52] << 8);
		
		for(uint8_t i=0;i<8;i++)
			Var_AddrRemapping(&gCount_Info[Count_sum].var_addr[i]);
	}
	else if (type == 1)
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		gCount_Info[Count_sum].v_add = (var[pointer + 1] + (var[pointer + 2] << 8));
		gCount_Info[Count_sum].t_add = var[pointer + 3] + (var[pointer + 4] << 8);
		gCount_Info[Count_sum].c_add = var[pointer + 5] + (var[pointer + 6] << 8);
		gCount_Info[Count_sum].x = var[pointer + 7] + (var[pointer + 8] << 8);
		gCount_Info[Count_sum].y = var[pointer + 9] + (var[pointer + 10] << 8);
		gCount_Info[Count_sum].ID_start = var[pointer + 11] + (var[pointer + 12] << 8);
		gCount_Info[Count_sum].dis_mode = var[pointer + 13];
		gCount_Info[Count_sum].dir = var[pointer + 14];
		gCount_Info[Count_sum].end_mode = var[pointer + 15];
		gCount_Info[Count_sum].end_feedback = var[pointer + 16];
		gCount_Info[Count_sum].var_addr[0] = var[pointer + 17] + (var[pointer + 18] << 8);
		gCount_Info[Count_sum].var[0] = var[pointer + 19] + (var[pointer + 20] << 8);
		gCount_Info[Count_sum].var_addr[1] = var[pointer + 21] + (var[pointer + 22] << 8);
		gCount_Info[Count_sum].var[1] = var[pointer + 23] + (var[pointer + 24] << 8);
		gCount_Info[Count_sum].var_addr[2] = var[pointer + 25] + (var[pointer + 26] << 8);
		gCount_Info[Count_sum].var[2] = var[pointer + 27] + (var[pointer + 28] << 8);
		gCount_Info[Count_sum].var_addr[3] = var[pointer + 29] + (var[pointer + 30] << 8);
		gCount_Info[Count_sum].var[3] = var[pointer + 31] + (var[pointer + 32] << 8);
		gCount_Info[Count_sum].var_addr[4] = var[pointer + 33] + (var[pointer + 34] << 8);
		gCount_Info[Count_sum].var[4] = var[pointer + 35] + (var[pointer + 36] << 8);
		gCount_Info[Count_sum].var_addr[5] = var[pointer + 37] + (var[pointer + 38] << 8);
		gCount_Info[Count_sum].var[5] = var[pointer + 39] + (var[pointer + 40] << 8);
		gCount_Info[Count_sum].var_addr[6] = var[pointer + 41] + (var[pointer + 42] << 8);
		gCount_Info[Count_sum].var[6] = var[pointer + 43] + (var[pointer + 44] << 8);
		gCount_Info[Count_sum].var_addr[7] = var[pointer + 45] + (var[pointer + 46] << 8);
		gCount_Info[Count_sum].var[7] = var[pointer + 47] + (var[pointer + 48] << 8);
		
		for(uint8_t i=0;i<8;i++)
			Var_AddrRemapping(&gCount_Info[Count_sum].var_addr[i]);
	}

	if (Pop_up_flag == 1) // Popup offset
	{
		gCount_Info[Count_sum].x += Pop_up_x;
		gCount_Info[Count_sum].y += Pop_up_y;
	}
	for (i = 0; i < Record_count; i++)
	{
		if (gCount_Info[Count_sum].v_add == gRecord_count_Info[i].v_add)
		{
			gRecord_count_Info[i].v_add = gRecord_count_Info[Record_count - 1].v_add;
			gRecord_count_Info[i].t_add = gRecord_count_Info[Record_count - 1].t_add;
			gRecord_count_Info[i].c_add = gRecord_count_Info[Record_count - 1].c_add;
			gRecord_count_Info[i].dir = gRecord_count_Info[Record_count - 1].dir;
			gRecord_count_Info[i].end_feedback = gRecord_count_Info[Record_count - 1].end_feedback;
			gRecord_count_Info[i].var[0] = gRecord_count_Info[Record_count - 1].var[0];
			gRecord_count_Info[i].var_addr[0] = gRecord_count_Info[Record_count - 1].var_addr[0];
			gRecord_count_Info[i].var[1] = gRecord_count_Info[Record_count - 1].var[1];
			gRecord_count_Info[i].var_addr[1] = gRecord_count_Info[Record_count - 1].var_addr[1];
			gRecord_count_Info[i].var[2] = gRecord_count_Info[Record_count - 1].var[2];
			gRecord_count_Info[i].var_addr[2] = gRecord_count_Info[Record_count - 1].var_addr[2];
			gRecord_count_Info[i].var[3] = gRecord_count_Info[Record_count - 1].var[3];
			gRecord_count_Info[i].var_addr[3] = gRecord_count_Info[Record_count - 1].var_addr[3];
			gRecord_count_Info[i].var[4] = gRecord_count_Info[Record_count - 1].var[4];
			gRecord_count_Info[i].var_addr[4] = gRecord_count_Info[Record_count - 1].var_addr[4];
			gRecord_count_Info[i].var[5] = gRecord_count_Info[Record_count - 1].var[5];
			gRecord_count_Info[i].var_addr[5] = gRecord_count_Info[Record_count - 1].var_addr[5];
			gRecord_count_Info[i].var[6] = gRecord_count_Info[Record_count - 1].var[6];
			gRecord_count_Info[i].var_addr[6] = gRecord_count_Info[Record_count - 1].var_addr[6];
			gRecord_count_Info[i].var[7] = gRecord_count_Info[Record_count - 1].var[7];
			gRecord_count_Info[i].var_addr[7] = gRecord_count_Info[Record_count - 1].var_addr[7];
			Record_count--;
		}
	}
	gCount_Info[Count_sum].last_w = 0;
	Display_Count(Count_sum);

	Count_sum++;
}

uint8_t Display_Count(uint8_t i)
{
	uint16_t ID[11];
	uint8_t buff[12] = {0};
	uint16_t temp;
	uint16_t x_time = 0;
	uint8_t j = 0, cnt = 0;

	if (((var[gCount_Info[i].c_add * 2] << 8) + var[gCount_Info[i].c_add * 2 + 1]) == 2)
	{
		if (gCount_Info[i].last_w > 0)
		{
			LT_ReadFlash_UI(buff, addr_index[10] + 12 * (gCount_Info[i].ID_start) + multi_language * 12 * addr_index[11], 12);
			pic_h = buff[6] + (buff[7] << 8);
			
			LT268_dispaly_CutPicture(gCount_Info[i].x, gCount_Info[i].y,
					 gCount_Info[i].x, gCount_Info[i].y, gCount_Info[i].last_w , pic_h,
					 LCD_XSIZE_TFT, FullScreen_addr, FullScreen_color, FullScreen_flag);
			
			gCount_Info[i].last_w = 0;
		}
		return 0;
	}
	if (gCount_Info[i].dis_mode == 0)
	{
		return 0;
	}
	else if (gCount_Info[i].dis_mode == 1) // Hour, minute and second
	{
		temp = (var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1];
		ID[0] = temp / 36000 % 10;
		ID[1] = temp / 3600 % 10;
		ID[2] = 10;
		temp = temp % 3600;
		ID[3] = temp / 600 % 10;
		ID[4] = temp / 60 % 10;
		ID[5] = 10;
		temp = temp % 60;
		ID[6] = temp / 10 % 10;
		ID[7] = temp % 10;
		cnt = 7;
	}
	else if (gCount_Info[i].dis_mode == 2)
	{
		temp = (var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1];

		ID[0] = temp / 36000 % 10;
		ID[1] = temp / 3600 % 10;
		ID[2] = 10;
		temp = temp % 3600;
		ID[3] = temp / 600 % 10;
		ID[4] = temp / 60 % 10;
		cnt = 4;
	}
	else if (gCount_Info[i].dis_mode == 3)
	{
		temp = (var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1];
		temp = temp % 3600;
		ID[0] = temp / 600 % 10;
		ID[1] = temp / 60 % 10;
		ID[2] = 10;
		temp = temp % 60;
		ID[3] = temp / 10 % 10;
		ID[4] = temp % 10;
		cnt = 4;
	}
	else if (gCount_Info[i].dis_mode == 4)
	{
		if (((var[gCount_Info[i].v_add * 2] << 8) + var[gCount_Info[i].v_add * 2 + 1]) > 10000)
		{
			temp = (var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1];
			ID[0] = temp / 10000 % 10;
			ID[1] = temp / 1000 % 10;
			ID[2] = temp / 100 % 10;
			ID[3] = temp / 10 % 10;
			ID[4] = temp % 10;
			cnt = 4;
		}
		else if (((var[gCount_Info[i].v_add * 2] << 8) + var[gCount_Info[i].v_add * 2 + 1]) > 1000)
		{
			temp = (var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1];
			ID[0] = temp / 1000 % 10;
			ID[1] = temp / 100 % 10;
			ID[2] = temp / 10 % 10;
			ID[3] = temp % 10;
			cnt = 3;
		}
		else if (((var[gCount_Info[i].v_add * 2] << 8) + var[gCount_Info[i].v_add * 2 + 1]) > 100)
		{
			temp = (var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1];
			ID[0] = temp / 100 % 10;
			ID[1] = temp / 10 % 10;
			ID[2] = temp % 10;
			cnt = 2;
		}
		else if (((var[gCount_Info[i].v_add * 2] << 8) + var[gCount_Info[i].v_add * 2 + 1]) > 10)
		{
			temp = (var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1];
			ID[0] = temp / 10 % 10;
			ID[1] = temp % 10;
			cnt = 1;
		}
		else
		{
			temp = (var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1];
			ID[0] = temp % 10;
			cnt = 0;
		}
	}
//	var_temp[gCount_Info[i].t_add * 2] = var[gCount_Info[i].t_add * 2];
//	var_temp[gCount_Info[i].t_add * 2 + 1] = var[gCount_Info[i].t_add * 2 + 1];

	/*On the keyboard input page*/
	if (DioKb_flag == 1)
	{
		if (!(gCount_Info[i].x > gDio_Info[Dio_num].Xe || (gCount_Info[i].x + x_time) < gDio_Info[Dio_num].Xs || gCount_Info[i].y > gDio_Info[Dio_num].Ye || (gCount_Info[i].y + pic_h) < gDio_Info[Dio_num].Ys))
		{
			return 0;
		}
	}
	else if (AioKb_flag == 1)
	{
		if (!(gCount_Info[i].x > gAio_Info[Aio_num].Xe || (gCount_Info[i].x + x_time) < gAio_Info[Aio_num].Xs || gCount_Info[i].y > gAio_Info[Aio_num].Ye || (gCount_Info[i].y + pic_h) < gAio_Info[Aio_num].Ys))
		{
			return 0;
		}
	}
	else if (GBKioKb_flag == 1)
	{
		if (!(gCount_Info[i].x > gGBKio_Info[GBKio_num].Xe || (gCount_Info[i].x + x_time) < gGBKio_Info[GBKio_num].Xs || gCount_Info[i].y > gGBKio_Info[GBKio_num].Ye || (gCount_Info[i].y + pic_h) < gGBKio_Info[GBKio_num].Ys))
		{
			return 0;
		}
	}

	for (j = 0; j <= cnt; j++)
	{
		if (gCount_Info[i].ID_start + ID[j] >= addr_index[11])
			continue; // picture is available
		LT_ReadFlash_UI(buff, addr_index[10] + 12 * (gCount_Info[i].ID_start + ID[j]) + multi_language * 12 * addr_index[11], 12);

		pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
		pic_w = buff[4] + (buff[5] << 8);
		pic_h = buff[6] + (buff[7] << 8);
		pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
		pic_flag = buff[11];

		if (pic_len != 0 && pic_flag != 0xFF) // picture is not empty
		{
			if (pic_flag == 0 || pic_flag == 1 || pic_flag == 2)
				LT_ShowPicture(gCount_Info[i].x + x_time, gCount_Info[i].y, pic_w, pic_h, pic_add, pic_len, pic_flag); 
			x_time += pic_w;
		}
	}

	gCount_Info[i].last_w = x_time;
}

void show_Count(void)
{
	if (Count_sum > 0 && Count_flag == 1)
	{
		Count_flag = 0;
		for (uint8_t i = 0; i < Count_sum; i++)
		{
			if (((var[gCount_Info[i].c_add * 2] << 8) + var[gCount_Info[i].c_add * 2 + 1]) != 0)
				Display_Count(i);
			else if (((var[gCount_Info[i].t_add * 2] << 8) + var[gCount_Info[i].t_add * 2 + 1]) !=
					 (var_temp[gCount_Info[i].t_add * 2] << 8) + var_temp[gCount_Info[i].t_add * 2 + 1])
				Display_Count(i);
		}
	}
}

void Saving_counting_parameters(void)
{
	uint8_t i, j;
	for (i = 0; i < Count_sum; i++)
	{
		if (Record_count > 0 && gCount_Info[i].end_mode == 1)
		{
			for (j = 0; j < Record_count; j++)
			{
				if (gCount_Info[i].v_add == gRecord_count_Info[j].v_add)
					break;
				if (j == Record_count - 1)
				{
					gRecord_count_Info[Record_count].v_add = gCount_Info[i].v_add;
					gRecord_count_Info[Record_count].t_add = gCount_Info[i].t_add;
					gRecord_count_Info[Record_count].c_add = gCount_Info[i].c_add;
					gRecord_count_Info[Record_count].dir = gCount_Info[i].dir;
					gRecord_count_Info[Record_count].end_feedback = gCount_Info[i].end_feedback;
					gRecord_count_Info[Record_count].var[0] = gCount_Info[i].var[0];
					gRecord_count_Info[Record_count].var_addr[0] = gCount_Info[i].var_addr[0];
					gRecord_count_Info[Record_count].var[1] = gCount_Info[i].var[1];
					gRecord_count_Info[Record_count].var_addr[1] = gCount_Info[i].var_addr[1];
					gRecord_count_Info[Record_count].var[2] = gCount_Info[i].var[2];
					gRecord_count_Info[Record_count].var_addr[2] = gCount_Info[i].var_addr[2];
					gRecord_count_Info[Record_count].var[3] = gCount_Info[i].var[3];
					gRecord_count_Info[Record_count].var_addr[3] = gCount_Info[i].var_addr[3];
					gRecord_count_Info[Record_count].var[4] = gCount_Info[i].var[4];
					gRecord_count_Info[Record_count].var_addr[4] = gCount_Info[i].var_addr[4];
					gRecord_count_Info[Record_count].var[5] = gCount_Info[i].var[5];
					gRecord_count_Info[Record_count].var_addr[5] = gCount_Info[i].var_addr[5];
					gRecord_count_Info[Record_count].var[6] = gCount_Info[i].var[6];
					gRecord_count_Info[Record_count].var_addr[6] = gCount_Info[i].var_addr[6];
					gRecord_count_Info[Record_count].var[7] = gCount_Info[i].var[7];
					gRecord_count_Info[Record_count].var_addr[7] = gCount_Info[i].var_addr[7];
					Record_count++;
				}
			}
		}
		else if (gCount_Info[i].end_mode == 1)
		{
			gRecord_count_Info[Record_count].v_add = gCount_Info[i].v_add;
			gRecord_count_Info[Record_count].t_add = gCount_Info[i].t_add;
			gRecord_count_Info[Record_count].c_add = gCount_Info[i].c_add;
			gRecord_count_Info[Record_count].dir = gCount_Info[i].dir;
			gRecord_count_Info[Record_count].end_feedback = gCount_Info[i].end_feedback;
			gRecord_count_Info[Record_count].var[0] = gCount_Info[i].var[0];
			gRecord_count_Info[Record_count].var_addr[0] = gCount_Info[i].var_addr[0];
			gRecord_count_Info[Record_count].var[1] = gCount_Info[i].var[1];
			gRecord_count_Info[Record_count].var_addr[1] = gCount_Info[i].var_addr[1];
			gRecord_count_Info[Record_count].var[2] = gCount_Info[i].var[2];
			gRecord_count_Info[Record_count].var_addr[2] = gCount_Info[i].var_addr[2];
			gRecord_count_Info[Record_count].var[3] = gCount_Info[i].var[3];
			gRecord_count_Info[Record_count].var_addr[3] = gCount_Info[i].var_addr[3];
			gRecord_count_Info[Record_count].var[4] = gCount_Info[i].var[4];
			gRecord_count_Info[Record_count].var_addr[4] = gCount_Info[i].var_addr[4];
			gRecord_count_Info[Record_count].var[5] = gCount_Info[i].var[5];
			gRecord_count_Info[Record_count].var_addr[5] = gCount_Info[i].var_addr[5];
			gRecord_count_Info[Record_count].var[6] = gCount_Info[i].var[6];
			gRecord_count_Info[Record_count].var_addr[6] = gCount_Info[i].var_addr[6];
			gRecord_count_Info[Record_count].var[7] = gCount_Info[i].var[7];
			gRecord_count_Info[Record_count].var_addr[7] = gCount_Info[i].var_addr[7];
			Record_count++;
		}
	}
}



/***********************************/
Var_Count_Info gVar_Count_Info[Var_count_size];
uint8_t Var_Count_num = 0;
uint8_t Var_Count_flag = 0;
/*��������*/
void Variable_Count(uint8_t type, uint8_t *buff)
{
	uint16_t pointer = 0;
	
	if (type == 0)
	{
		gVar_Count_Info[Var_Count_num].v_add = (buff[5] + (buff[6] << 8));
		gVar_Count_Info[Var_Count_num].v_type = buff[7];
		gVar_Count_Info[Var_Count_num].c_add = buff[8] + (buff[9] << 8);
		gVar_Count_Info[Var_Count_num].V_loop = buff[10] + (buff[11] << 8);
		gVar_Count_Info[Var_Count_num].V_once = buff[12] + (buff[13] << 8);
		gVar_Count_Info[Var_Count_num].V_stop = buff[14] + (buff[15] << 8);
		gVar_Count_Info[Var_Count_num].Vmin = ((long long)((buff[16] << 24) + (buff[17] << 16) + (buff[18] << 8) + buff[19]) << 32) 
												| (long long)((buff[20] << 24) + (buff[21] << 16) + (buff[22] << 8) + buff[23]);
		gVar_Count_Info[Var_Count_num].Vmax = ((long long)((buff[24] << 24) + (buff[25] << 16) + (buff[26] << 8) + buff[27]) << 32) 
											| (long long)((buff[28] << 24) + (buff[29] << 16) + (buff[30] << 8) + buff[31]);
		gVar_Count_Info[Var_Count_num].step = buff[32] + (buff[33] << 8);
		gVar_Count_Info[Var_Count_num].t_d = buff[34] + (buff[35] << 8);
		gVar_Count_Info[Var_Count_num].t_c = 0;
		gVar_Count_Info[Var_Count_num].var_addr[0] = buff[36] + (buff[37] << 8);
		gVar_Count_Info[Var_Count_num].var[0] = buff[38] + (buff[39] << 8);
		gVar_Count_Info[Var_Count_num].var_addr[1] = buff[40] + (buff[41] << 8);
		gVar_Count_Info[Var_Count_num].var[1] = buff[42] + (buff[43] << 8);
		gVar_Count_Info[Var_Count_num].var_addr[2] = buff[44] + (buff[45] << 8);
		gVar_Count_Info[Var_Count_num].var[2] = buff[46] + (buff[47] << 8);
		gVar_Count_Info[Var_Count_num].var_addr[3] = buff[48] + (buff[49] << 8);
		gVar_Count_Info[Var_Count_num].var[3] = buff[50] + (buff[51] << 8);
		gVar_Count_Info[Var_Count_num].var_addr[4] = buff[52] + (buff[53] << 8);
		gVar_Count_Info[Var_Count_num].var[4] = buff[54] + (buff[55] << 8);
		gVar_Count_Info[Var_Count_num].var_addr[5] = buff[56] + (buff[57] << 8);
		gVar_Count_Info[Var_Count_num].var[5] = buff[58] + (buff[59] << 8);
		gVar_Count_Info[Var_Count_num].var_addr[6] = buff[60] + (buff[61] << 8);
		gVar_Count_Info[Var_Count_num].var[6] = buff[62] + (buff[63] << 8);
		gVar_Count_Info[Var_Count_num].var_addr[7] = buff[64] + (buff[65] << 8);
		gVar_Count_Info[Var_Count_num].var[7] = buff[66] + (buff[67] << 8);
		gVar_Count_Info[Var_Count_num].mode = buff[68];
		gVar_Count_Info[Var_Count_num].feedback = buff[69];
		
		Var_AddrRemapping(&gVar_Count_Info[Var_Count_num].v_add);
		
		for(uint8_t i=0;i<8;i++)
			Var_AddrRemapping(&gVar_Count_Info[Var_Count_num].var_addr[i]);
			
	}
	else if (type == 1)
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		gVar_Count_Info[Var_Count_num].v_add = var[pointer + 1] + (var[pointer + 2] << 8);
		gVar_Count_Info[Var_Count_num].v_type = var[pointer + 3];
		gVar_Count_Info[Var_Count_num].c_add = var[pointer + 4] + (var[pointer + 5] << 8);
		gVar_Count_Info[Var_Count_num].V_loop = var[pointer + 6] + (var[pointer + 7] << 8);
		gVar_Count_Info[Var_Count_num].V_once = var[pointer + 8] + (var[pointer + 9] << 8);
		gVar_Count_Info[Var_Count_num].V_stop = var[pointer + 10] + (var[pointer + 11] << 8);
		gVar_Count_Info[Var_Count_num].Vmin = ((long long)((var[pointer + 12] << 24) + (var[pointer + 13] << 16) + (var[pointer + 14] << 8) + var[pointer + 15]) << 32)
											| (long long)((var[pointer + 16] << 24) + (var[pointer + 17] << 16) + (var[pointer + 18] << 8) + var[pointer + 19]);
		gVar_Count_Info[Var_Count_num].Vmax = ((long long)((var[pointer + 20] << 24) + (var[pointer + 21] << 16) + (var[pointer + 22] << 8) + var[pointer + 23]) << 32) 
											| (long long)((var[pointer + 24] << 24) + (var[pointer + 25] << 16) + (var[pointer + 26] << 8) + var[pointer + 27]);
		gVar_Count_Info[Var_Count_num].step = var[pointer + 28] + (var[pointer + 29] << 8);
		gVar_Count_Info[Var_Count_num].t_d = var[pointer + 30] + (var[pointer + 31] << 8);
		gVar_Count_Info[Var_Count_num].t_c = 0;
		gVar_Count_Info[Var_Count_num].var_addr[0] = var[pointer + 32] + (var[pointer + 33] << 8);
		gVar_Count_Info[Var_Count_num].var[0] = var[pointer + 34] + (var[pointer + 35] << 8);
		gVar_Count_Info[Var_Count_num].var_addr[1] = var[pointer + 36] + (var[pointer + 37] << 8);
		gVar_Count_Info[Var_Count_num].var[1] = var[pointer + 38] + (var[pointer + 39] << 8);
		gVar_Count_Info[Var_Count_num].var_addr[2] = var[pointer + 40] + (var[pointer + 41] << 8);
		gVar_Count_Info[Var_Count_num].var[2] = var[pointer + 42] + (var[pointer + 43] << 8);
		gVar_Count_Info[Var_Count_num].var_addr[3] = var[pointer + 44] + (var[pointer + 45] << 8);
		gVar_Count_Info[Var_Count_num].var[3] = var[pointer + 46] + (var[pointer + 47] << 8);
		gVar_Count_Info[Var_Count_num].var_addr[4] = var[pointer + 48] + (var[pointer + 49] << 8);
		gVar_Count_Info[Var_Count_num].var[4] = var[pointer + 50] + (var[pointer + 51] << 8);
		gVar_Count_Info[Var_Count_num].var_addr[5] = var[pointer + 52] + (var[pointer + 53] << 8);
		gVar_Count_Info[Var_Count_num].var[5] = var[pointer + 54] + (var[pointer + 55] << 8);
		gVar_Count_Info[Var_Count_num].var_addr[6] = var[pointer + 56] + (var[pointer + 57] << 8);
		gVar_Count_Info[Var_Count_num].var[6] = var[pointer + 58] + (var[pointer + 59] << 8);
		gVar_Count_Info[Var_Count_num].var_addr[7] = var[pointer + 60] + (var[pointer + 61] << 8);
		gVar_Count_Info[Var_Count_num].var[7] = var[pointer + 62] + (var[pointer + 63] << 8);
		gVar_Count_Info[Var_Count_num].mode = var[pointer + 64];
		gVar_Count_Info[Var_Count_num].feedback = var[pointer + 65];
		
		Var_AddrRemapping(&gVar_Count_Info[Var_Count_num].v_add);
		
		for(uint8_t i=0;i<8;i++)
			Var_AddrRemapping(&gVar_Count_Info[Var_Count_num].var_addr[i]);
	}
	
	Var_Count_num ++;
}

void Run_Var_Count(uint8_t num)
{
	uint8_t finish = 0;
	uint8_t rebuf[20];
	
	int8_t sum1 = 0;
	int16_t sum2 = 0;
	int32_t sum4 = 0;
	long long temp = 0;

	if (gVar_Count_Info[num].v_type == 0 )
	{
		temp = var[gVar_Count_Info[num].v_add * 2 + 1];
	}
	else if(gVar_Count_Info[num].v_type == 0x80 )
	{
		sum1 = var[gVar_Count_Info[num].v_add * 2 + 1];
		temp = sum1;
	}
	else if (gVar_Count_Info[num].v_type == 1) 
	{
		temp = (var[gVar_Count_Info[num].v_add * 2] << 8) + var[gVar_Count_Info[num].v_add * 2 + 1];
	}
	else if (gVar_Count_Info[num].v_type == 0x81) 
	{
		sum2 = (var[gVar_Count_Info[num].v_add * 2] << 8) + var[gVar_Count_Info[num].v_add * 2 + 1];
		temp = sum2;
	}
	else if (gVar_Count_Info[num].v_type == 2)
	{
		temp = (var[gVar_Count_Info[num].v_add * 2] << 24) + (var[gVar_Count_Info[num].v_add * 2 + 1] << 16) + (var[gVar_Count_Info[num].v_add * 2 + 2] << 8) + var[gVar_Count_Info[num].v_add * 2 + 3];
	}
	else if (gVar_Count_Info[num].v_type == 0x82)
	{
		sum4 = (var[gVar_Count_Info[num].v_add * 2] << 24) + (var[gVar_Count_Info[num].v_add * 2 + 1] << 16) + (var[gVar_Count_Info[num].v_add * 2 + 2] << 8) + var[gVar_Count_Info[num].v_add * 2 + 3];
		temp = sum4;
	}
	else if (gVar_Count_Info[num].v_type == 3 || gVar_Count_Info[num].v_type == 0x83)
	{
		temp = ((long long)((var[gVar_Count_Info[num].v_add * 2] << 24) + (var[gVar_Count_Info[num].v_add * 2 + 1] << 16) + (var[gVar_Count_Info[num].v_add * 2 + 2] << 8) + var[gVar_Count_Info[num].v_add * 2 + 3]) << 32);
		temp = temp | (long long)((var[gVar_Count_Info[num].v_add * 2 + 4] << 24) + (var[gVar_Count_Info[num].v_add * 2 + 5] << 16) + (var[gVar_Count_Info[num].v_add * 2 + 6] << 8) + var[gVar_Count_Info[num].v_add * 2 + 7]);
	}
	if ((var[gVar_Count_Info[num].c_add * 2] << 8) + var[gVar_Count_Info[num].c_add * 2 + 1] == gVar_Count_Info[num].V_loop)
	{
		if (gVar_Count_Info[num].mode == 1)	//+
		{
			if (temp + gVar_Count_Info[num].step < gVar_Count_Info[num].Vmin || temp >= gVar_Count_Info[num].Vmax)
			{
				temp = gVar_Count_Info[num].Vmin;
			}
			else if (temp <  gVar_Count_Info[num].Vmax && temp + gVar_Count_Info[num].step > gVar_Count_Info[num].Vmax)
				temp = gVar_Count_Info[num].Vmax;
			else
				temp += gVar_Count_Info[num].step;
			
		}
		else if (gVar_Count_Info[num].mode == 0)
		{
			if (temp - gVar_Count_Info[num].step < gVar_Count_Info[num].Vmin && temp > gVar_Count_Info[num].Vmin)
				temp = gVar_Count_Info[num].Vmin;
			else if (temp - gVar_Count_Info[num].step >  gVar_Count_Info[num].Vmax || temp <= gVar_Count_Info[num].Vmin)
				temp = gVar_Count_Info[num].Vmax;
			else
				temp -= gVar_Count_Info[num].step;
		}
	}
	else if ((var[gVar_Count_Info[num].c_add * 2] << 8) + var[gVar_Count_Info[num].c_add * 2 + 1] == gVar_Count_Info[num].V_once)
	{

		if (gVar_Count_Info[num].mode == 1)	//+
		{
			if (temp + gVar_Count_Info[num].step < gVar_Count_Info[num].Vmin)
				temp = gVar_Count_Info[num].Vmin;
			else if (temp + gVar_Count_Info[num].step > gVar_Count_Info[num].Vmax)
				temp = gVar_Count_Info[num].Vmax;
			else
				temp += gVar_Count_Info[num].step;
			if (temp == gVar_Count_Info[num].Vmax)
				finish = 1;
			
		}
		else if (gVar_Count_Info[num].mode == 0)	//-
		{
			if (temp - gVar_Count_Info[num].step < gVar_Count_Info[num].Vmin)
				temp = gVar_Count_Info[num].Vmin;
			else if (temp - gVar_Count_Info[num].step > gVar_Count_Info[num].Vmax)
				temp = gVar_Count_Info[num].Vmax;
			else
				temp -= gVar_Count_Info[num].step;
			
			if (temp == gVar_Count_Info[num].Vmin)
				finish = 1;
		}
	}
	
	if (gVar_Count_Info[num].v_type == 0 || gVar_Count_Info[num].v_type == 0x80)
	{
		var[gVar_Count_Info[num].v_add * 2 + 1] = temp & 0xFF;
	}
	else if (gVar_Count_Info[num].v_type == 1 || gVar_Count_Info[num].v_type == 0x81)
	{
		var[gVar_Count_Info[num].v_add * 2] = (temp >> 8) & 0xFF;
		var[gVar_Count_Info[num].v_add * 2 + 1] = temp & 0xFF;
	}
	else if (gVar_Count_Info[num].v_type == 2 || gVar_Count_Info[num].v_type == 0x82)
	{
		var[gVar_Count_Info[num].v_add * 2] = (temp >> 24) & 0xFF;
		var[gVar_Count_Info[num].v_add * 2 + 1] = (temp >> 16) & 0xFF;
		var[gVar_Count_Info[num].v_add * 2 + 2] = (temp >> 8) & 0xFF;
		var[gVar_Count_Info[num].v_add * 2 + 3] = temp & 0xFF;
	}
	else if (gVar_Count_Info[num].v_type == 3 || gVar_Count_Info[num].v_type == 0x83)
	{
		var[gVar_Count_Info[num].v_add * 2] = temp >> 56 & 0xFF;
		var[gVar_Count_Info[num].v_add * 2 + 1] = temp >> 48 & 0xFF;
		var[gVar_Count_Info[num].v_add * 2 + 2] = temp >> 40 & 0xFF;
		var[gVar_Count_Info[num].v_add * 2 + 3] = temp >> 32 & 0xFF;
		var[gVar_Count_Info[num].v_add * 2 + 4] = temp >> 24 & 0xFF;
		var[gVar_Count_Info[num].v_add * 2 + 5] = temp >> 16 & 0xFF;
		var[gVar_Count_Info[num].v_add * 2 + 6] = temp >> 8 & 0xFF;
		var[gVar_Count_Info[num].v_add * 2 + 7] = temp & 0xFF;
	}
	
	if (gVar_Count_Info[num].v_add >= VAR_ADDR_S)
		reg_operation(gVar_Count_Info[num].v_add);
	page_date_update(pic_id);
	
	if (finish == 1)
	{
		var[gVar_Count_Info[num].c_add * 2] = (gVar_Count_Info[num].V_stop >> 8) & 0xFF;
		var[gVar_Count_Info[num].c_add * 2 + 1] = gVar_Count_Info[num].V_stop  & 0xFF;
		
		
		if (gVar_Count_Info[num].feedback == 1)
		{
			if (gVar_Count_Info[num].v_type == 0x00 || 
				gVar_Count_Info[num].v_type == 0x80 || 
				gVar_Count_Info[num].v_type == 0x01 || 
				gVar_Count_Info[num].v_type == 0x81)
			{
				rebuf[3] = 0x41;
				rebuf[4] = gVar_Count_Info[num].v_add >> 8;;
				rebuf[5] = gVar_Count_Info[num].v_add & 0xFF;;
				rebuf[6] = var[gVar_Count_Info[num].v_add * 2];
				rebuf[7] = var[gVar_Count_Info[num].v_add * 2 + 1];
				LT_SendData_CRC_Frame(rebuf, 5);
			}
			else if (gVar_Count_Info[num].v_type == 0x02 || gVar_Count_Info[num].v_type == 0x82)
			{
				rebuf[3] = 0x41;
				rebuf[4] = gVar_Count_Info[num].v_add >> 8;;
				rebuf[5] = gVar_Count_Info[num].v_add & 0xFF;;
				rebuf[6] = var[gVar_Count_Info[num].v_add * 2];
				rebuf[7] = var[gVar_Count_Info[num].v_add * 2 + 1];
				rebuf[8] = var[gVar_Count_Info[num].v_add * 2 + 2];
				rebuf[9] = var[gVar_Count_Info[num].v_add * 2 + 3];
				LT_SendData_CRC_Frame(rebuf, 7);
			}
			else if (gVar_Count_Info[num].v_type == 0x03 || gVar_Count_Info[num].v_type == 0x83)
			{
				rebuf[3] = 0x41;
				rebuf[4] = gVar_Count_Info[num].v_add >> 8;;
				rebuf[5] = gVar_Count_Info[num].v_add & 0xFF;;
				rebuf[6] = var[gVar_Count_Info[num].v_add * 2];
				rebuf[7] = var[gVar_Count_Info[num].v_add * 2 + 1];
				rebuf[8] = var[gVar_Count_Info[num].v_add * 2 + 2];
				rebuf[9] = var[gVar_Count_Info[num].v_add * 2 + 3];
				rebuf[10] = var[gVar_Count_Info[num].v_add * 2 + 4];
				rebuf[11] = var[gVar_Count_Info[num].v_add * 2 + 5];
				rebuf[12] = var[gVar_Count_Info[num].v_add * 2 + 6];
				rebuf[13] = var[gVar_Count_Info[num].v_add * 2 + 7];
				LT_SendData_CRC_Frame(rebuf, 11);
			}			
		}
		
		for (uint8_t i = 0; i < 8; i++)
		{
			if (gVar_Count_Info[num].var_addr[i] != 0xFFFF && gVar_Count_Info[num].var_addr[i] < VAR_ADDR_E)
			{
				var[gVar_Count_Info[num].var_addr[i] * 2] = (gVar_Count_Info[num].var[i] >> 8) & 0xFF;
				var[gVar_Count_Info[num].var_addr[i] * 2 + 1] = gVar_Count_Info[num].var[i] & 0xFF;

				if (gVar_Count_Info[num].var_addr[i] >= VAR_ADDR_S)
				{
					uint16_t ppage = pic_id;
					reg_operation(gVar_Count_Info[num].var_addr[i]);
					if(ppage!=pic_id) return ;
				}
			}
		}
		page_date_update(pic_id);
	}
}


void Check_Var_Count(void)
{
	if (Var_Count_num > 0 && Var_Count_flag == 1)
	{
		Var_Count_flag = 0;
		for (uint8_t i = 0; i < Var_Count_num; i++)
			gVar_Count_Info[i].t_c++;
		for (uint8_t i = 0; i < Var_Count_num; i++)
		{
			if (gVar_Count_Info[i].t_c >= gVar_Count_Info[i].t_d)
			{
				if ((var[gVar_Count_Info[i].c_add * 2] << 8) + var[gVar_Count_Info[i].c_add * 2 + 1] == gVar_Count_Info[i].V_loop
					|| (var[gVar_Count_Info[i].c_add * 2] << 8) + var[gVar_Count_Info[i].c_add * 2 + 1] == gVar_Count_Info[i].V_once)
				Run_Var_Count(i); // When a window timing time expires, switch pictures
				gVar_Count_Info[i].t_c = 0;
			}
		}
	}
}



/************************/




/***********************************************************************************
 * Function Name : pop_up_touch
 * Description   : Touch detection of pop-up window.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void pop_up_touch(void)
{
	uint8_t i = 0;
	uint8_t rebuf[20];
	uint16_t w, h;

	// press down.202406
	if (gTpInfo.sta)
	{

		for (i = 0; i < Pop_up_count; i++)
		{
			if (gTpInfo.x[0] >= gPop_up_Info[i].Xs && gTpInfo.y[0] >= gPop_up_Info[i].Ys &&
				gTpInfo.x[0] <= gPop_up_Info[i].Xe && gTpInfo.y[0] <= gPop_up_Info[i].Ye &&
				Pop_up_press == 0 && button_Press_flag == 0)
			{
				if (gPop_up_Info[i].press_id != 0xFFFF)
				{
					Display_Icon(gPop_up_Info[i].press_id, gPop_up_Info[i].Xs, gPop_up_Info[i].Ys, 0);
				}

				if (Pop_up_flag == 0)
				{
					if ((gPop_up_Info[i].function & 0x01) == 1)
					{
					}
					else
					{
					}
				}
				Pop_up_num = i;
				button_Press_flag = 1;
				Pop_up_press = 1;
				// Pop_up_flag = 1;
				if (buzzer)
					touch_buzzer();
			}
		}
	}

	if (Button_Key_Code_Flag == 1)
	{
		for (i = 0; i < Pop_up_count; i++)
		{
			if (gPop_up_Info[i].Xs == 0xFFFF && Button_Key_Code == gPop_up_Info[i].Ys)
			{

				Button_Key_Code_Flag = 0;
				Button_Key_Code = 0;
				if (Pop_up_flag == 0)
				{
					// reserve
					if ((gPop_up_Info[i].function & 0x01) == 1)
					{
					}
					else
					{
					}
				}
				Pop_up_num = i;
				button_Press_flag = 1;
				Pop_up_press = 1;
				// Pop_up_flag = 1;
				break;
			}
		}
	}

	if (gTpInfo.sta == 0 && Pop_up_press == 1)
	{
		if (gPop_up_Info[Pop_up_num].Code == 0xC008)
		{
			rebuf[3] = 0x41;
			rebuf[4] = 0xFF;
			rebuf[5] = 0xFF;
			rebuf[6] = gPop_up_Info[Pop_up_num].Keyvalue >> 8;
			rebuf[7] = gPop_up_Info[Pop_up_num].Keyvalue & 0xFF;
			LT_SendData_CRC_Frame(rebuf, 5);
		}

		Pop_up_flag = 0;
		if (gPop_up_Info[Pop_up_num].id != 0xFFFF)
		{
			Display_Icon(gPop_up_Info[Pop_up_num].id, gPop_up_Info[Pop_up_num].Xs, gPop_up_Info[Pop_up_num].Ys, 0);
		}
		Pop_up_flag = 1;

		if (gPop_up_Info[Pop_up_num].function & 0x02)
		{
		}

		Pop_up_x = gPop_up_Info[Pop_up_num].pop_up_x;
		Pop_up_y = gPop_up_Info[Pop_up_num].pop_up_y;
		Pop_up_id = gPop_up_Info[Pop_up_num].pop_up_id;

//		 printf("Pop_up_num=%d \r\n",Pop_up_num);
//		 printf("Pop_up_xy= %d  %d  id  %d  \r\n",Pop_up_x,Pop_up_y,Pop_up_id);
		if (gPop_up_Info[Pop_up_num].pop_up_id != 0xFFFF)
		{
			Display_pop_up(gPop_up_Info[Pop_up_num].pop_up_id, gPop_up_Info[Pop_up_num].pop_up_x, gPop_up_Info[Pop_up_num].pop_up_y);
		}

		Pop_up_press = 0;
		button_Press_flag = 0;
	}
}

/***********************************************************************************
 * Function Name : Basic_touch
 * Description   : Touch detection of Basic_touch.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Basic_touch(void)
{
	uint8_t i = 0;
	uint8_t rebuf[20];

	if (gTpInfo.sta) // press down//202406
	{
		//printf("888888888887777777777777777777\r\n");
		for (i = 0; i < Basci_count; i++)
		{
			if (gTpInfo.x[0] >= gBasci_Info[i].Xs && gTpInfo.y[0] >= gBasci_Info[i].Ys &&
				gTpInfo.x[0] <= gBasci_Info[i].Xe && gTpInfo.y[0] <= gBasci_Info[i].Ye &&
				Basci_flag == 0 && button_Press_flag == 0)
			{
			  //printf(" Basic_touch    = %d     \r\n",Basci_num);
			  /* if(pic_id==0&&i==0)//蓝牙
				{
					//printf("11111111111111111111111111111111\r\n");
                    var[0x020A*2] = 0X00;
			        var[0x020A*2+1] = 0X02;	
					rebuf[0] = 0x40;
					rebuf[1] = 0x8C;
					rebuf[2] = 0xC0;	
					LT_SendData_CRC_Frame(rebuf, 3);
				}
			  if(pic_id==0&&i==1)//HDMI
				{
					//printf("22222222222222222222222222222222\r\n");
                    var[0x020A*2] = 0X00;
			        var[0x020A*2+1] = 0X04;						
					rebuf[0] = 0x40;
					rebuf[1] = 0x90;//0x90
					rebuf[2] = 0xC0;	
					LT_SendData_CRC_Frame(rebuf, 3);
				}
			  if(pic_id==0&&i==2)//唱歌
				{
					//printf("333333333333333333333333333333333\r\n");
                    var[0x020A*2] = 0X00;
			        var[0x020A*2+1] = 0X01;						
					rebuf[0] = 0x40;
					rebuf[1] = 0x8A;
					rebuf[2] = 0xC0;	
					LT_SendData_CRC_Frame(rebuf, 3);
				}
			  if(pic_id==0&&i==3)//电影
				{
					//printf("4444444444444444444444444444444444\r\n");
                    var[0x020A*2] = 0X00;
			        var[0x020A*2+1] = 0X00;					
					rebuf[0] = 0x40;
					rebuf[1] = 0x8B;
					rebuf[2] = 0xC0;	
					LT_SendData_CRC_Frame(rebuf, 3);
				}*/
				if (gBasci_Info[i].press_id != 0xFFFF)
				{
					Display_Icon(gBasci_Info[i].press_id, gBasci_Info[i].Xs, gBasci_Info[i].Ys, 0);
				}
				Basci_num = i;
				Basci_flag = 1;
				button_Press_flag = 1;
				if (buzzer)
					touch_buzzer();
			}
		}
	}
	
	if (Button_Key_Code_Flag == 1)
	{
		for (i = 0; i < Basci_count; i++)
		{
			if (gBasci_Info[i].Xs == 0xFFFF && gBasci_Info[i].Ys ==  Button_Key_Code)
			{
				Button_Key_Code_Flag = 0;
				Button_Key_Code = 0;
				if (gBasci_Info[i].Code == 0xC001)
				{
					rebuf[3] = 0x41;
					rebuf[4] = 0xFF;
					rebuf[5] = 0xFF;
					rebuf[6] = gBasci_Info[i].Keyvalue >> 8;
					rebuf[7] = gBasci_Info[i].Keyvalue & 0xFF;
					LT_SendData_CRC_Frame(rebuf, 5);
				}

				if (gBasci_Info[i].Next_id != 0xFFFF)
				{
					Display_page(gBasci_Info[i].Next_id);
				}
				break;
			}
		}
	}
	
	// raise
	if (gTpInfo.sta == 0 && Basci_flag == 1)
	{
		if (gBasci_Info[Basci_num].Code == 0xC001)
		{
			rebuf[3] = 0x41;
			rebuf[4] = 0xFF;
			rebuf[5] = 0xFF;
			rebuf[6] = gBasci_Info[Basci_num].Keyvalue >> 8;
			rebuf[7] = gBasci_Info[Basci_num].Keyvalue & 0xFF;
			LT_SendData_CRC_Frame(rebuf, 5);
		}
		if (gBasci_Info[Basci_num].id != 0xFFFF)
		{
			Display_Icon(gBasci_Info[Basci_num].id, gBasci_Info[Basci_num].Xs, gBasci_Info[Basci_num].Ys, 0);
		}
		Basci_flag = 0;
		button_Press_flag = 0;
		if (gBasci_Info[Basci_num].Next_id != 0xFFFF)
		{
			Display_page(gBasci_Info[Basci_num].Next_id);
		}
	}
}

/***********************************************************************************
 * Function Name : Adj_touch
 * Description   : Touch detection of variable adjustment.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Adj_touch(void)
{
	uint8_t i = 0, rebuf[20], num = 0;
//	int8_t sum0 = 0;
//	int16_t sum1 = 0;
	int32_t sum0 = 0;
	int32_t sum1 = 0;
	int32_t sum = 0;

	if (gTpInfo.sta) // press down变量调节
	{
		for (i = 0; i < Adj_count; i++)
		{
			if (gTpInfo.x[0] >= gAdj_Info[i].Xs && gTpInfo.y[0] >= gAdj_Info[i].Ys &&
				gTpInfo.x[0] <= gAdj_Info[i].Xe && gTpInfo.y[0] <= gAdj_Info[i].Ye &&
				Adj_flag == 0 && button_Press_flag == 0)
			{
				//printf("/********1212121212***********pic_id:%d,i:%d/\r\n",pic_id,i);
				/*if(pic_id==0&&i==0)
				{
                 Display_page(1);
				}
				else if(pic_id==1&&i==0)
				{
                 Display_page(0);				 
				}*/
				if (gAdj_Info[i].press_id != 0xFFFF)
				{
					Display_Icon(gAdj_Info[i].press_id, gAdj_Info[i].Xs, gAdj_Info[i].Ys, 0);
				}
				Adj_num = i;
				Adj_flag = 1;
				button_Press_flag = 1;
				if (gAdj_Info[i].key_mode == 1)
					Adj_loop = 1;

				if (buzzer)
					touch_buzzer();
			}
		}
	}

	if (((Adj_loop == 1 && Adj_time > 50)||(Adj_loop == 2 && Adj_time > 10)) && gTpInfo.sta == 1 && Adj_flag == 1)
	{
		Adj_loop = 2;
		Adj_time = 0;
		if (gAdj_Info[Adj_num].p_tpye == 0x00)
			sum = var[gAdj_Info[Adj_num].p_add * 2 + 1];
		else if (gAdj_Info[Adj_num].p_tpye == 0x80)
		{
			sum0 = var[gAdj_Info[Adj_num].p_add * 2 + 1];
			sum = sum0;
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x01)
			sum = (var[gAdj_Info[Adj_num].p_add * 2] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 1];
		else if (gAdj_Info[Adj_num].p_tpye == 0x81)
		{
			sum1 = (var[gAdj_Info[Adj_num].p_add * 2] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 1];
			sum = sum1;
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x02)
		{
			if (var[gAdj_Info[Adj_num].p_add * 2] >= 0x80)
				var[gAdj_Info[Adj_num].p_add * 2] = 0x40;
			sum = (var[gAdj_Info[Adj_num].p_add * 2] << 24) +
				  (var[gAdj_Info[Adj_num].p_add * 2 + 1] << 16) +
				  (var[gAdj_Info[Adj_num].p_add * 2 + 2] << 8) +
				  var[gAdj_Info[Adj_num].p_add * 2 + 3];
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x82)
			sum = (var[gAdj_Info[Adj_num].p_add * 2] << 24) +
				  (var[gAdj_Info[Adj_num].p_add * 2 + 1] << 16) +
				  (var[gAdj_Info[Adj_num].p_add * 2 + 2] << 8) +
				  var[gAdj_Info[Adj_num].p_add * 2 + 3];

		else if (gAdj_Info[Adj_num].p_tpye == 0x83)
		{
			sum = (var[gAdj_Info[Adj_num].p_add * 2 + 6] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 7];
			if (var[gAdj_Info[Adj_num].p_add * 2] >= 0x80)
				sum = sum + (0x80 << 24);
		}
		else if (gAdj_Info[Adj_num].p_tpye >= 0x40 && gAdj_Info[Adj_num].p_tpye <= 0x4F)
			sum = (var[gAdj_Info[Adj_num].p_add * 2] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 1];

		if (gAdj_Info[Adj_num].Adj_mode == 1) //+
		{
			if (gAdj_Info[Adj_num].p_tpye & 0x40)
			{
				num = gAdj_Info[Adj_num].p_tpye & 0x0F;
				if (sum & (1 << num))
					sum &= ~(1 << num);
				else
					sum |= (1 << num);
			}
			else
			{
				sum += gAdj_Info[Adj_num].Adj_step;

				if ((gAdj_Info[Adj_count].p_tpye & 0x80) > 0)
				{
					if (sum > gAdj_Info[Adj_num].V_max)
					{
						if (gAdj_Info[Adj_num].Return_Mode == 0)
							sum = gAdj_Info[Adj_num].V_max;
						else
							sum = gAdj_Info[Adj_num].V_min;
					}
					else if (sum < gAdj_Info[Adj_num].V_min)
					{
						sum = gAdj_Info[Adj_num].V_min;
					}
				}
				else
				{
					if (sum > gAdj_Info[Adj_num].V_max1)
					{
						if (gAdj_Info[Adj_num].Return_Mode == 0)
							sum = gAdj_Info[Adj_num].V_max1;
						else
							sum = gAdj_Info[Adj_num].V_min1;
					}
					else if (sum < gAdj_Info[Adj_num].V_min1)
					{
						sum = gAdj_Info[Adj_num].V_min1;
					}
				}
			}
		}
		else // -
		{
			if (gAdj_Info[Adj_num].p_tpye & 0x40)
			{
				num = gAdj_Info[Adj_num].p_tpye & 0x0F;
				if (sum & (1 << num))
					sum &= ~(1 << num);
				else
					sum |= (1 << num);
			}
			else
			{
				sum -= gAdj_Info[Adj_num].Adj_step;
				if ((gAdj_Info[Adj_count].p_tpye & 0x80) > 0)
				{
					if (sum < gAdj_Info[Adj_num].V_min)
					{
						if (gAdj_Info[Adj_num].Return_Mode == 0)
							sum = gAdj_Info[Adj_num].V_min;
						else
							sum = gAdj_Info[Adj_num].V_max;
					}
					else if (sum > gAdj_Info[Adj_num].V_max)
						sum = gAdj_Info[Adj_num].V_max;
				}
				else
				{
					if (sum < gAdj_Info[Adj_num].V_min1)
					{
						if (gAdj_Info[Adj_num].Return_Mode == 0)
							sum = gAdj_Info[Adj_num].V_min1;
						else
							sum = gAdj_Info[Adj_num].V_max1;
					}
					else if (sum > gAdj_Info[Adj_num].V_max1)
						sum = gAdj_Info[Adj_num].V_max1;
				}
			}
		}



		if (gAdj_Info[Adj_num].p_tpye == 0x00 || gAdj_Info[Adj_num].p_tpye == 0x80)
		{
			var[gAdj_Info[Adj_num].p_add * 2 + 1] = sum;
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x01 || gAdj_Info[Adj_num].p_tpye == 0x81)
		{
			var[gAdj_Info[Adj_num].p_add * 2] = sum >> 8 & 0xFF;
			var[gAdj_Info[Adj_num].p_add * 2 + 1] = sum & 0xFF;
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x02 || gAdj_Info[Adj_num].p_tpye == 0x82)
		{
			if (sum < 0)
			{
				var[gAdj_Info[Adj_num].p_add * 2] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 1] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 2] = sum >> 8 & 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 3] = sum & 0xFF;
			}
			else
			{
				var[gAdj_Info[Adj_num].p_add * 2] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 1] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 2] = sum >> 8 & 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 3] = sum & 0xFF;
			}
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x83)
		{
			if (sum < 0)
			{
				var[gAdj_Info[Adj_num].p_add * 2] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 1] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 2] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 3] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 4] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 5] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 6] = sum >> 8 & 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 7] = sum & 0xFF;
			}
			else
			{
				var[gAdj_Info[Adj_num].p_add * 2] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 1] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 2] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 3] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 4] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 5] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 6] = sum >> 8 & 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 7] = sum & 0xFF;
			}
		}
		else if (gAdj_Info[Adj_num].p_tpye >= 0x40 && gAdj_Info[Adj_num].p_tpye <= 0x4F)
		{
			var[gAdj_Info[Adj_num].p_add * 2] = sum >> 8 & 0xFF;
			var[gAdj_Info[Adj_num].p_add * 2 + 1] = sum & 0xFF;
		}

		if (gAdj_Info[Adj_num].p_add >= VAR_ADDR_S)
			reg_operation(gAdj_Info[Adj_num].p_add);

		page_date_update(pic_id);
	}



	if (Button_Key_Code_Flag == 1)   
	{
		for (i = 0; i < Adj_count; i++)
		{
			if (gAdj_Info[i].Xs == 0xFFFF && gAdj_Info[i].Ys ==  Button_Key_Code)
			{
				Button_Key_Code_Flag = 0;
				Button_Key_Code = 0;
				if (gAdj_Info[i].p_tpye == 0x00)
					sum = var[gAdj_Info[i].p_add * 2 + 1];
				else if (gAdj_Info[i].p_tpye == 0x80)
				{
					sum0 = var[gAdj_Info[i].p_add * 2 + 1];
					sum = sum0;
				}
				else if (gAdj_Info[i].p_tpye == 0x01)
					sum = (var[gAdj_Info[i].p_add * 2] << 8) + var[gAdj_Info[i].p_add * 2 + 1];
				else if (gAdj_Info[i].p_tpye == 0x81)
				{
					sum1 = (var[gAdj_Info[i].p_add * 2] << 8) + var[gAdj_Info[i].p_add * 2 + 1];
					sum = sum1;
				}
				else if (gAdj_Info[i].p_tpye == 0x02)
				{
					if (var[gAdj_Info[i].p_add * 2] >= 0x80)
						var[gAdj_Info[i].p_add * 2] = 0x40;
					sum = (var[gAdj_Info[i].p_add * 2] << 24) +
						  (var[gAdj_Info[i].p_add * 2 + 1] << 16) +
						  (var[gAdj_Info[i].p_add * 2 + 2] << 8) +
						  var[gAdj_Info[i].p_add * 2 + 3];
				}
				else if (gAdj_Info[i].p_tpye == 0x82)
					sum = (var[gAdj_Info[i].p_add * 2] << 24) +
						  (var[gAdj_Info[i].p_add * 2 + 1] << 16) +
						  (var[gAdj_Info[i].p_add * 2 + 2] << 8) +
						  var[gAdj_Info[i].p_add * 2 + 3];
				else if (gAdj_Info[i].p_tpye == 0x83)
				{
					sum = (var[gAdj_Info[i].p_add * 2 + 6] << 8) + var[gAdj_Info[i].p_add * 2 + 7];
					if (var[gAdj_Info[i].p_add * 2] >= 0x80)
						sum = sum + (0x80 << 24);
				}
				else if (gAdj_Info[i].p_tpye >= 0x40 && gAdj_Info[i].p_tpye <= 0x4F)
					sum = (var[gAdj_Info[i].p_add * 2] << 8) + var[gAdj_Info[i].p_add * 2 + 1];

				if (gAdj_Info[Adj_num].Adj_mode == 1) //+
				{
					if (gAdj_Info[Adj_num].p_tpye & 0x40)
					{
						num = gAdj_Info[Adj_num].p_tpye & 0x0F;
						if (sum & (1 << num))
							sum &= ~(1 << num);
						else
							sum |= (1 << num);
					}
					else
					{
						sum += gAdj_Info[Adj_num].Adj_step;

						if ((gAdj_Info[Adj_count].p_tpye & 0x80) > 0)
						{
							if (sum > gAdj_Info[Adj_num].V_max)
							{
								if (gAdj_Info[Adj_num].Return_Mode == 0)
									sum = gAdj_Info[Adj_num].V_max;
								else
									sum = gAdj_Info[Adj_num].V_min;
							}
							else if (sum < gAdj_Info[Adj_num].V_min)
							{
								sum = gAdj_Info[Adj_num].V_min;
							}
						}
						else
						{
							if (sum > gAdj_Info[Adj_num].V_max1)
							{
								if (gAdj_Info[Adj_num].Return_Mode == 0)
									sum = gAdj_Info[Adj_num].V_max1;
								else
									sum = gAdj_Info[Adj_num].V_min1;
							}
							else if (sum < gAdj_Info[Adj_num].V_min1)
							{
								sum = gAdj_Info[Adj_num].V_min1;
							}
						}
					}
				}
				else // -
				{
					if (gAdj_Info[Adj_num].p_tpye & 0x40)
					{
						num = gAdj_Info[Adj_num].p_tpye & 0x0F;
						if (sum & (1 << num))
							sum &= ~(1 << num);
						else
							sum |= (1 << num);
					}
					else
					{
						sum -= gAdj_Info[Adj_num].Adj_step;
						if ((gAdj_Info[Adj_count].p_tpye & 0x80) > 0)
						{
							if (sum < gAdj_Info[Adj_num].V_min)
							{
								if (gAdj_Info[Adj_num].Return_Mode == 0)
									sum = gAdj_Info[Adj_num].V_min;
								else
									sum = gAdj_Info[Adj_num].V_max;
							}
							else if (sum > gAdj_Info[Adj_num].V_max)
								sum = gAdj_Info[Adj_num].V_max;
						}
						else
						{
							if (sum < gAdj_Info[Adj_num].V_min1)
							{
								if (gAdj_Info[Adj_num].Return_Mode == 0)
									sum = gAdj_Info[Adj_num].V_min1;
								else
									sum = gAdj_Info[Adj_num].V_max1;
							}
							else if (sum > gAdj_Info[Adj_num].V_max1)
								sum = gAdj_Info[Adj_num].V_max1;
						}
					}
				}



				if (gAdj_Info[i].p_tpye == 0x00 || gAdj_Info[i].p_tpye == 0x80)
				{

					var[gAdj_Info[i].p_add * 2 + 1] = sum & 0xFF;
				}
				else if (gAdj_Info[i].p_tpye == 0x01 || gAdj_Info[i].p_tpye == 0x81)
				{
					var[gAdj_Info[i].p_add * 2] = sum >> 8 & 0xFF;
					var[gAdj_Info[i].p_add * 2 + 1] = sum & 0xFF;
				}
				else if (gAdj_Info[i].p_tpye == 0x02 || gAdj_Info[i].p_tpye == 0x82)
				{

					if (sum < 0)
					{
						var[gAdj_Info[i].p_add * 2] = 0xFF;
						var[gAdj_Info[i].p_add * 2 + 1] = 0xFF;
						var[gAdj_Info[i].p_add * 2 + 2] = sum >> 8 & 0xFF;
						var[gAdj_Info[i].p_add * 2 + 3] = sum & 0xFF;
					}
					else
					{
						var[gAdj_Info[i].p_add * 2] = 0;
						var[gAdj_Info[i].p_add * 2 + 1] = 0;
						var[gAdj_Info[i].p_add * 2 + 2] = sum >> 8 & 0xFF;
						var[gAdj_Info[i].p_add * 2 + 3] = sum & 0xFF;
					}
				}
				else if (gAdj_Info[i].p_tpye == 0x83)
				{
					if (sum < 0)
					{
						var[gAdj_Info[i].p_add * 2] = 0xFF;
						var[gAdj_Info[i].p_add * 2 + 1] = 0xFF;
						var[gAdj_Info[i].p_add * 2 + 2] = 0xFF;
						var[gAdj_Info[i].p_add * 2 + 3] = 0xFF;
						var[gAdj_Info[i].p_add * 2 + 4] = 0xFF;
						var[gAdj_Info[i].p_add * 2 + 5] = 0xFF;
						var[gAdj_Info[i].p_add * 2 + 6] = sum >> 8 & 0xFF;
						var[gAdj_Info[i].p_add * 2 + 7] = sum & 0xFF;
					}
					else
					{
						var[gAdj_Info[i].p_add * 2] = 0;
						var[gAdj_Info[i].p_add * 2 + 1] = 0;
						var[gAdj_Info[i].p_add * 2 + 2] = 0;
						var[gAdj_Info[i].p_add * 2 + 3] = 0;
						var[gAdj_Info[i].p_add * 2 + 4] = 0;
						var[gAdj_Info[i].p_add * 2 + 5] = 0;
						var[gAdj_Info[i].p_add * 2 + 6] = sum >> 8 & 0xFF;
						var[gAdj_Info[i].p_add * 2 + 7] = sum & 0xFF;
					}
				}
				else if (gAdj_Info[i].p_tpye >= 0x40 && gAdj_Info[i].p_tpye <= 0x4F)
				{
					var[gAdj_Info[i].p_add * 2] = sum >> 8 & 0xFF;
					var[gAdj_Info[i].p_add * 2 + 1] = sum & 0xFF;
				}

				if (gAdj_Info[i].Code == 0xC003) // Enable serial port return
				{
					rebuf[3] = 0x41;
					if (gAdj_Info[i].p_tpye == 0x00 ||
						gAdj_Info[i].p_tpye == 0x80 ||
						gAdj_Info[i].p_tpye == 0x01 ||
						gAdj_Info[i].p_tpye == 0x81 ||
						(gAdj_Info[i].p_tpye >= 0x40 && gAdj_Info[i].p_tpye <= 0x4F))
					{
						rebuf[4] = gAdj_Info[i].p_add >> 8;
						rebuf[5] = gAdj_Info[i].p_add & 0xFF;
						rebuf[6] = var[gAdj_Info[i].p_add * 2];
						rebuf[7] = var[gAdj_Info[i].p_add * 2 + 1];
						LT_SendData_CRC_Frame(rebuf, 5);
					}
					else if (gAdj_Info[i].p_tpye == 0x02 || gAdj_Info[i].p_tpye == 0x82)
					{
						rebuf[4] = gAdj_Info[i].p_add >> 8;
						rebuf[5] = gAdj_Info[i].p_add & 0xFF;
						rebuf[6] = var[gAdj_Info[i].p_add * 2];
						rebuf[7] = var[gAdj_Info[i].p_add * 2 + 1];
						rebuf[8] = var[gAdj_Info[i].p_add * 2 + 2];
						rebuf[9] = var[gAdj_Info[i].p_add * 2 + 3];
						LT_SendData_CRC_Frame(rebuf, 7);
					}
					else if (gAdj_Info[i].p_tpye == 0x03 || gAdj_Info[i].p_tpye == 0x83)
					{
						rebuf[4] = gAdj_Info[i].p_add >> 8;
						rebuf[5] = gAdj_Info[i].p_add & 0xFF;
						rebuf[6] = var[gAdj_Info[i].p_add * 2];
						rebuf[7] = var[gAdj_Info[i].p_add * 2 + 1];
						rebuf[8] = var[gAdj_Info[i].p_add * 2 + 2];
						rebuf[9] = var[gAdj_Info[i].p_add * 2 + 3];
						rebuf[10] = var[gAdj_Info[i].p_add * 2 + 4];
						rebuf[11] = var[gAdj_Info[i].p_add * 2 + 5];
						rebuf[12] = var[gAdj_Info[i].p_add * 2 + 6];
						rebuf[13] = var[gAdj_Info[i].p_add * 2 + 7];
						LT_SendData_CRC_Frame(rebuf, 11);
					}
				}

				if (gAdj_Info[i].id != 0xFFFF)
				{
					Display_Icon(gAdj_Info[i].id, gAdj_Info[i].Xs, gAdj_Info[i].Ys, 0);
				}

				if (gAdj_Info[i].p_add >= VAR_ADDR_S)
					reg_operation(gAdj_Info[i].p_add);

				page_date_update(pic_id);
				break;
			}
		}
	}
	if (gTpInfo.sta == 0 && Adj_flag == 1)
	{
		if (gAdj_Info[Adj_num].p_tpye == 0x00)
			sum = var[gAdj_Info[Adj_num].p_add * 2 + 1];
		else if (gAdj_Info[Adj_num].p_tpye == 0x80)
		{
			sum0 = var[gAdj_Info[Adj_num].p_add * 2 + 1];
			sum = sum0;
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x01)
			sum = (var[gAdj_Info[Adj_num].p_add * 2] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 1];
		else if (gAdj_Info[Adj_num].p_tpye == 0x81)
		{
			sum1 = (var[gAdj_Info[Adj_num].p_add * 2] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 1];
			sum = sum1;
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x02)
		{
			if (var[gAdj_Info[Adj_num].p_add * 2] >= 0x80)
				var[gAdj_Info[Adj_num].p_add * 2] = 0x40;
			sum = (var[gAdj_Info[Adj_num].p_add * 2] << 24) +
				  (var[gAdj_Info[Adj_num].p_add * 2 + 1] << 16) +
				  (var[gAdj_Info[Adj_num].p_add * 2 + 2] << 8) +
				  var[gAdj_Info[Adj_num].p_add * 2 + 3];
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x82)
			sum = (var[gAdj_Info[Adj_num].p_add * 2] << 24) +
				  (var[gAdj_Info[Adj_num].p_add * 2 + 1] << 16) +
				  (var[gAdj_Info[Adj_num].p_add * 2 + 2] << 8) +
				  var[gAdj_Info[Adj_num].p_add * 2 + 3];
		else if (gAdj_Info[Adj_num].p_tpye == 0x83)
		{
			sum = (var[gAdj_Info[Adj_num].p_add * 2 + 6] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 7];
			if (var[gAdj_Info[Adj_num].p_add * 2] >= 0x80)
				sum = sum + (0x80 << 24);
		}
		else if (gAdj_Info[Adj_num].p_tpye >= 0x40 && gAdj_Info[Adj_num].p_tpye <= 0x4F)
			sum = (var[gAdj_Info[Adj_num].p_add * 2] << 8) + var[gAdj_Info[Adj_num].p_add * 2 + 1];

		if (gAdj_Info[Adj_num].Adj_mode == 1) //+
				{
					if (gAdj_Info[Adj_num].p_tpye & 0x40)
					{
						num = gAdj_Info[Adj_num].p_tpye & 0x0F;
						if (sum & (1 << num))
							sum &= ~(1 << num);
						else
							sum |= (1 << num);
					}
					else
					{
						sum += gAdj_Info[Adj_num].Adj_step;

						if ((gAdj_Info[Adj_num].p_tpye & 0x80) > 0)
						{
							if (sum > gAdj_Info[Adj_num].V_max)
							{
								if (gAdj_Info[Adj_num].Return_Mode == 0)
									sum = gAdj_Info[Adj_num].V_max;
								else
									sum = gAdj_Info[Adj_num].V_min;
							}
							else if (sum < gAdj_Info[Adj_num].V_min)
							{
								sum = gAdj_Info[Adj_num].V_min;
							}
						}
						else
						{
							if (sum > gAdj_Info[Adj_num].V_max1)
							{
								if (gAdj_Info[Adj_num].Return_Mode == 0)
									sum = gAdj_Info[Adj_num].V_max1;
								else
									sum = gAdj_Info[Adj_num].V_min1;
							}
							else if (sum < gAdj_Info[Adj_num].V_min1)
							{
								sum = gAdj_Info[Adj_num].V_min1;
							}
						}
					}
				}
				else // -
				{
					if (gAdj_Info[Adj_num].p_tpye & 0x40)
					{
						num = gAdj_Info[Adj_num].p_tpye & 0x0F;
						if (sum & (1 << num))
							sum &= ~(1 << num);
						else
							sum |= (1 << num);
					}
					else
					{
						sum -= gAdj_Info[Adj_num].Adj_step;
						if ((gAdj_Info[Adj_num].p_tpye & 0x80) > 0)
						{
							if (sum < gAdj_Info[Adj_num].V_min)
							{
								if (gAdj_Info[Adj_num].Return_Mode == 0)
									sum = gAdj_Info[Adj_num].V_min;
								else
									sum = gAdj_Info[Adj_num].V_max;
							}
							else if (sum > gAdj_Info[Adj_num].V_max)
								sum = gAdj_Info[Adj_num].V_max;
						}
						else
						{
							if (sum < gAdj_Info[Adj_num].V_min1)
							{
								if (gAdj_Info[Adj_num].Return_Mode == 0)
									sum = gAdj_Info[Adj_num].V_min1;
								else
									sum = gAdj_Info[Adj_num].V_max1;
							}
							else if (sum > gAdj_Info[Adj_num].V_max1)
								sum = gAdj_Info[Adj_num].V_max1;
						}
					}
				}

		if (gAdj_Info[Adj_num].p_tpye == 0x00 || gAdj_Info[Adj_num].p_tpye == 0x80)
		{

			var[gAdj_Info[Adj_num].p_add * 2 + 1] = sum & 0xFF;
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x01 || gAdj_Info[Adj_num].p_tpye == 0x81)
		{

			var[gAdj_Info[Adj_num].p_add * 2] = sum >> 8 & 0xFF;
			var[gAdj_Info[Adj_num].p_add * 2 + 1] = sum & 0xFF;
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x02 || gAdj_Info[Adj_num].p_tpye == 0x82)
		{

			if (sum < 0)
			{
				var[gAdj_Info[Adj_num].p_add * 2] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 1] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 2] = sum >> 8 & 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 3] = sum & 0xFF;
			}
			else
			{
				var[gAdj_Info[Adj_num].p_add * 2] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 1] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 2] = sum >> 8 & 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 3] = sum & 0xFF;
			}
		}
		else if (gAdj_Info[Adj_num].p_tpye == 0x83)
		{
			if (sum < 0)
			{
				var[gAdj_Info[Adj_num].p_add * 2] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 1] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 2] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 3] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 4] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 5] = 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 6] = sum >> 8 & 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 7] = sum & 0xFF;
			}
			else
			{
				var[gAdj_Info[Adj_num].p_add * 2] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 1] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 2] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 3] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 4] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 5] = 0;
				var[gAdj_Info[Adj_num].p_add * 2 + 6] = sum >> 8 & 0xFF;
				var[gAdj_Info[Adj_num].p_add * 2 + 7] = sum & 0xFF;
			}
		}
		else if (gAdj_Info[Adj_num].p_tpye >= 0x40 && gAdj_Info[Adj_num].p_tpye <= 0x4F)
		{
			var[gAdj_Info[Adj_num].p_add * 2] = sum >> 8 & 0xFF;
			var[gAdj_Info[Adj_num].p_add * 2 + 1] = sum & 0xFF;
		}

		if (gAdj_Info[Adj_num].Code == 0xC003) // Enable serial port return
		{
			rebuf[3] = 0x41;
			if (gAdj_Info[Adj_num].p_tpye == 0x00 ||
				gAdj_Info[Adj_num].p_tpye == 0x80 ||
				gAdj_Info[Adj_num].p_tpye == 0x01 ||
				gAdj_Info[Adj_num].p_tpye == 0x81 ||
				(gAdj_Info[Adj_num].p_tpye >= 0x40 && gAdj_Info[Adj_num].p_tpye <= 0x4F))
			{
				rebuf[4] = gAdj_Info[Adj_num].p_add >> 8;
				rebuf[5] = gAdj_Info[Adj_num].p_add & 0xFF;
				rebuf[6] = var[gAdj_Info[Adj_num].p_add * 2];
				rebuf[7] = var[gAdj_Info[Adj_num].p_add * 2 + 1];
				LT_SendData_CRC_Frame(rebuf, 5);
			}
			else if (gAdj_Info[Adj_num].p_tpye == 0x02 || gAdj_Info[Adj_num].p_tpye == 0x82)
			{
				rebuf[4] = gAdj_Info[Adj_num].p_add >> 8;
				rebuf[5] = gAdj_Info[Adj_num].p_add & 0xFF;
				rebuf[6] = var[gAdj_Info[Adj_num].p_add * 2];
				rebuf[7] = var[gAdj_Info[Adj_num].p_add * 2 + 1];
				rebuf[8] = var[gAdj_Info[Adj_num].p_add * 2 + 2];
				rebuf[9] = var[gAdj_Info[Adj_num].p_add * 2 + 3];
				LT_SendData_CRC_Frame(rebuf, 7);
			}
			else if (gAdj_Info[Adj_num].p_tpye == 0x03 || gAdj_Info[Adj_num].p_tpye == 0x83)
			{
				rebuf[4] = gAdj_Info[Adj_num].p_add >> 8;
				rebuf[5] = gAdj_Info[Adj_num].p_add & 0xFF;
				rebuf[6] = var[gAdj_Info[Adj_num].p_add * 2];
				rebuf[7] = var[gAdj_Info[Adj_num].p_add * 2 + 1];
				rebuf[8] = var[gAdj_Info[Adj_num].p_add * 2 + 2];
				rebuf[9] = var[gAdj_Info[Adj_num].p_add * 2 + 3];
				rebuf[10] = var[gAdj_Info[Adj_num].p_add * 2 + 4];
				rebuf[11] = var[gAdj_Info[Adj_num].p_add * 2 + 5];
				rebuf[12] = var[gAdj_Info[Adj_num].p_add * 2 + 6];
				rebuf[13] = var[gAdj_Info[Adj_num].p_add * 2 + 7];
				LT_SendData_CRC_Frame(rebuf, 11);
			}
		}

		if (gAdj_Info[Adj_num].id != 0xFFFF)
		{
			Display_Icon(gAdj_Info[Adj_num].id, gAdj_Info[Adj_num].Xs, gAdj_Info[Adj_num].Ys, 0);
		}
		button_Press_flag = 0;
		Adj_flag = 0;
		Adj_loop = 0;
		Adj_time = 0;
		if (gAdj_Info[Adj_num].p_add >= VAR_ADDR_S)
			reg_operation(gAdj_Info[Adj_num].p_add);

		page_date_update(pic_id);
	}
}

/***********************************************************************************
 * Function Name : VarKey_touch
 * Description   : Touch detection of multivariable adjustment.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void VarKey_touch(void)
{
	uint8_t i = 0;
	uint8_t rebuf[50];

	// press down多变量202406
	if (gTpInfo.sta) // press down
	{
		for (i = 0; i < VarKey_count; i++)
		{
			if (gTpInfo.x[0] >= gVarKey_Info[i].Xs && gTpInfo.y[0] >= gVarKey_Info[i].Ys &&
				gTpInfo.x[0] <= gVarKey_Info[i].Xe && gTpInfo.y[0] <= gVarKey_Info[i].Ye &&
				VarKey_flag == 0 && button_Press_flag == 0)
			{

				if (gVarKey_Info[i].press_id != 0xFFFF)
					Display_Icon(gVarKey_Info[i].press_id, gVarKey_Info[i].Xs, gVarKey_Info[i].Ys, 0);
			   /*if(pic_id==0&&VarKey_num==0)
				{
                    var[0x000A*2] = 0X00;
			        var[0x000A*2+1] = 0X01;	
					rebuf[0] = 0x40;
					rebuf[1] = 0x8D;
					rebuf[2] = 0xC0;	
					LT_SendData_CRC_Frame(rebuf, 3);
				}
			  if(pic_id==0&&VarKey_num==1)
				{
                    var[0x000A*2] = 0X00;
			        var[0x000A*2+1] = 0X02;						
					rebuf[0] = 0x40;
					rebuf[1] = 0x8C;
					rebuf[2] = 0xC0;	
					LT_SendData_CRC_Frame(rebuf, 3);
				}
			  if(pic_id==0&&VarKey_num==2)
				{
                    var[0x000A*2] = 0X00;
			        var[0x000A*2+1] = 0X04;						
					rebuf[0] = 0x40;
					rebuf[1] = 0x8A;
					rebuf[2] = 0xC0;	
					LT_SendData_CRC_Frame(rebuf, 3);
				}
			  if(pic_id==0&&VarKey_num==3)
				{
                    var[0x000A*2] = 0X00;
			        var[0x000A*2+1] = 0X03;					
					rebuf[0] = 0x40;
					rebuf[1] = 0x8B;
					rebuf[2] = 0xC0;	
					LT_SendData_CRC_Frame(rebuf, 3);
				}*/

				VarKey_num = i;
				VarKey_flag = 1;
				button_Press_flag = 1;
				if (buzzer)
					touch_buzzer();
			}
		}
	}
	
	if (Button_Key_Code_Flag == 1)
	{
		for (i = 0; i < VarKey_count; i++)
		{
			if (gVarKey_Info[i].Xs == 0xFFFF && gVarKey_Info[i].Ys ==  Button_Key_Code)
			{
				Button_Key_Code_Flag = 0;
				Button_Key_Code = 0;
				VarKey_num = i;
				for (i = 0; i < 8; i++)
				{
					if (gVarKey_Info[VarKey_num].var_addr[i] != 0xFFFF && gVarKey_Info[VarKey_num].var_addr[i] <= VAR_ADDR_E)
					{
						var[gVarKey_Info[VarKey_num].var_addr[i] * 2] = (gVarKey_Info[VarKey_num].var[i] >> 8) & 0xFF;
						var[gVarKey_Info[VarKey_num].var_addr[i] * 2 + 1] = gVarKey_Info[VarKey_num].var[i] & 0xFF;

						if (gVarKey_Info[VarKey_num].var_addr[i] >= VAR_ADDR_S)
						{
							reg_operation(gVarKey_Info[VarKey_num].var_addr[i]);
						}
					}
				}
				Get_date_variable_Id_Regular_update(pic_id);

				if (gVarKey_Info[VarKey_num].Code == 0xC00B)
				{
					rebuf[3] = 0x41;
					for (i = 0; i < 8; i++)
					{
						rebuf[4 * i + 4] = gVarKey_Info[VarKey_num].var_addr[i] >> 8;
						rebuf[4 * i + 5] = gVarKey_Info[VarKey_num].var_addr[i] & 0xFF;
						rebuf[4 * i + 6] = gVarKey_Info[VarKey_num].var[i] >> 8;
						rebuf[4 * i + 7] = gVarKey_Info[VarKey_num].var[i] & 0xFF;
						Var_AddrToReg(&rebuf[4 * i + 1]);
					}
					LT_SendData_CRC_Frame(rebuf, 33);
				}

				if (gVarKey_Info[VarKey_num].Next_id != 0xFFFF)
					Display_page(gVarKey_Info[VarKey_num].Next_id);
				break;
			}
		}
	}
	
	// raise
	if (gTpInfo.sta == 0 && VarKey_flag == 1)
	{
		if (gVarKey_Info[VarKey_num].id != 0xFFFF)
		{
			Display_Icon(gVarKey_Info[VarKey_num].id, gVarKey_Info[VarKey_num].Xs, gVarKey_Info[VarKey_num].Ys, 0);
		}
		button_Press_flag = 0;
		VarKey_flag = 0;

		for (i = 0; i < 8; i++)
		{
			if (gVarKey_Info[VarKey_num].var_addr[i] != 0xFFFF && gVarKey_Info[VarKey_num].var_addr[i] <= VAR_ADDR_E)
			{
				var[gVarKey_Info[VarKey_num].var_addr[i] * 2] = (gVarKey_Info[VarKey_num].var[i] >> 8) & 0xFF;
				var[gVarKey_Info[VarKey_num].var_addr[i] * 2 + 1] = gVarKey_Info[VarKey_num].var[i] & 0xFF;

				if (gVarKey_Info[VarKey_num].var_addr[i] >= VAR_ADDR_S)
				{
					reg_operation(gVarKey_Info[VarKey_num].var_addr[i]);
				}
			}
		}
		if (gVarKey_Info[VarKey_num].Code == 0xC00B)
		{
			rebuf[3] = 0x41;
			for (i = 0; i < 8; i++)
			{
				rebuf[4 * i + 4] = gVarKey_Info[VarKey_num].var_addr[i] >> 8;
				rebuf[4 * i + 5] = gVarKey_Info[VarKey_num].var_addr[i] & 0xFF;
				rebuf[4 * i + 6] = gVarKey_Info[VarKey_num].var[i] >> 8;
				rebuf[4 * i + 7] = gVarKey_Info[VarKey_num].var[i] & 0xFF;
				Var_AddrToReg(&rebuf[4 * i + 1]);
			}
			LT_SendData_CRC_Frame(rebuf, 33);
		}
		if (gVarKey_Info[VarKey_num].Next_id != 0xFFFF)
			Display_page(gVarKey_Info[VarKey_num].Next_id);
	}
}

#define GESTURE_THRESHOLD 50	  // Gesture effective sliding threshold
uint8_t Gesture_press = 0;		  // Gesture effective press/release
uint8_t Gesture_direction = 0xFF; // Gesture direction
uint8_t Gesture_flag = 0;		  // Gesture function on/off
/***********************************************************************************
 * Function Name : Gesture_touch
 * Description   : Touch detection of gesture.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Gesture_touch(void)
{
	uint8_t i = 0;
	int16_t Gesture_X, Gesture_Y;
	uint8_t rebuf[20];

	// press down
//	if (gTpInfo.sta && button_Press_flag==0)
	if (gTpInfo.sta && Gesture_press==0)
	{
		// sustain
		Gesture_X = gTpInfo.x[0] - First_pressX;
		Gesture_Y = gTpInfo.y[0] - First_pressY;
		if (Gesture_X >= 25 || Gesture_X <= -25 || Gesture_Y >= 25 || Gesture_Y <= -25)
		{
			Gesture_press = 1;
			
			// cancel
			Basci_flag = 0;
			Adj_flag = 0;
			Slide_flag = 0;
			Dio_flag = 0;
			AioKb_flag = 0;
			GBKioKb_flag = 0;
			Kb_flag = 0;
//			sldmenu_flag = 0;
			VarKey_flag = 0;
			Pop_up_flag = 0;
//			button_Press_flag = 1;
		}
	}

	
	// raise
	if (gTpInfo.sta == 0 && Gesture_press == 1)
	{
		Gesture_press = 0;
		button_Press_flag = 0;
		Gesture_X = gTpInfo.x[0] - First_pressX;
		Gesture_Y = gTpInfo.y[0] - First_pressY;
		if (Gesture_X >= GESTURE_THRESHOLD || Gesture_X <= -GESTURE_THRESHOLD || Gesture_Y >= GESTURE_THRESHOLD || Gesture_Y <= -GESTURE_THRESHOLD)
		{
			if (abs(Gesture_Y) > abs(Gesture_X))
			{
				if (Gesture_Y < 0)
					Gesture_direction = 0; // up
				else
					Gesture_direction = 1; // down
			}
			else
			{
				if (Gesture_X < 0)
					Gesture_direction = 2; // left
				else
					Gesture_direction = 3; // right
			}
		}

		if (Gesture_direction != 0xFF)
		{
			if (gGesture_Info.page[Gesture_direction] != 0xFFFF)
			{
				Gesture_flag = 0;
				if (gGesture_Info.Code == 0xC000)
				{
					rebuf[3] = 0x41;
					rebuf[4] = 0xFF;
					rebuf[5] = 0xFF;
					rebuf[6] = (gGesture_Info.value[Gesture_direction] >> 8) & 0xFF;
					rebuf[7] = gGesture_Info.value[Gesture_direction] & 0xFF;
					LT_SendData_CRC_Frame(rebuf, 5);
				}
				Display_page(gGesture_Info.page[Gesture_direction]);
			}

			Gesture_direction = 0xFF;
		}
	}
}

/***********************************************************************************
 * Function Name : Disp_slide
 * Description   : Display sliding progress bar.
 * Input         : - i: which number of sliding progress bar
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Disp_slide(uint8_t i)
{
    uint8_t buff[12] = {0};
    int16_t sum = 0;
    uint16_t w, h;
    uint16_t bgw, bgh;

    // progress bar is empty
    if (gSlide_Info[i].slideid == 0xFFFF) return;

    // touch icon
    if (gSlide_Info[i].arrowid != 0xFFFF)
    {
        LT_ReadFlash_UI(buff, addr_index[10] + 12 * gSlide_Info[i].arrowid + multi_language * 12 * addr_index[11], 12);
        PICINFO[2].addr = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
        PICINFO[2].w = buff[4] + (buff[5] << 8);
        PICINFO[2].h = buff[6] + (buff[7] << 8);
        PICINFO[2].flag = buff[11];
    }
    else
    {
        PICINFO[2].w = 0;
        PICINFO[2].h = 0;
        PICINFO[2].w = 0;
        PICINFO[2].h = 0;
    }

    // progress bar
    LT_ReadFlash_UI(buff, addr_index[10] + 12 * gSlide_Info[i].slideid + multi_language * 12 * addr_index[11], 12);
    pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
    pic_w = buff[4] + (buff[5] << 8);
    pic_h = buff[6] + (buff[7] << 8);
    pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
    pic_flag = buff[11];

    PICINFO[1].addr = pic_add;
    PICINFO[1].w = pic_w;
    PICINFO[1].h = pic_h;
    PICINFO[1].flag = pic_flag;
    PICINFO[1].x = gSlide_Info[i].x2;
    PICINFO[1].y = gSlide_Info[i].y2;

    // progress bar background
    if (gSlide_Info[i].bgid != 0xFFFF)
    {
        LT_ReadFlash_UI(buff, addr_index[10] + 12 * gSlide_Info[i].bgid + multi_language * 12 * addr_index[11], 12);
        PICINFO[0].addr = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
        PICINFO[0].w = buff[4] + (buff[5] << 8);
        PICINFO[0].h = buff[6] + (buff[7] << 8);
        PICINFO[0].len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
        PICINFO[0].flag = buff[11];

        PICINFO[0].x = gSlide_Info[i].x1;
        PICINFO[0].y = gSlide_Info[i].y1;

        // full-screen background
        if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
        {
//            LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
//                                PICINFO[0].x, PICINFO[0].y, LCD_XSIZE_TFT, FullScreen_addr,
//                                PICINFO[0].w, PICINFO[0].h, FullScreen_flag);
            LT268_BG_to_buffer(0, 0, PICINFO[0].w, m_PngData,
                                PICINFO[0].x, PICINFO[0].y, PICINFO[0].w, PICINFO[0].h);
        }

        // progress bar
        LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
                            0, 0, PICINFO[0].w, PICINFO[0].addr,
                            PICINFO[0].w, PICINFO[0].h, PICINFO[0].flag);

        // progress bar
        PICINFO[1].x = PICINFO[1].x - PICINFO[0].x;
        PICINFO[1].y = PICINFO[1].y - PICINFO[0].y;

        // touch icon
        if (gSlide_Info[i].direction == 0 || gSlide_Info[i].direction == 1)
        {
            if (PICINFO[2].h < PICINFO[1].h)
                PICINFO[2].y = PICINFO[1].y + (PICINFO[1].h - PICINFO[2].h) / 2;
            else
                PICINFO[2].y = PICINFO[1].y - (PICINFO[2].h - PICINFO[1].h) / 2;
            if (gSlide_Info[i].arrowid != 0xFFFF)
            {
                if(gSlide_Info[i].Xs - PICINFO[0].x < PICINFO[2].w/2)
                    gSlide_Info[i].Xs = PICINFO[0].x + PICINFO[2].w/2;
                if(PICINFO[0].x + PICINFO[0].w - gSlide_Info[i].Xe < PICINFO[2].w/2)
                    gSlide_Info[i].Xe = PICINFO[0].x + PICINFO[0].w - PICINFO[2].w/2;
            }
        }
        else if (gSlide_Info[i].direction == 2 || gSlide_Info[i].direction == 3)
        {
            if (PICINFO[2].w < PICINFO[1].w)
                PICINFO[2].x = PICINFO[1].x + (PICINFO[1].w - PICINFO[2].w) / 2;
            else
                PICINFO[2].x = PICINFO[1].x - (PICINFO[2].w - PICINFO[1].w) / 2;
            if (gSlide_Info[i].arrowid != 0xFFFF)
            {
                if(gSlide_Info[i].Ys - PICINFO[0].y < PICINFO[2].h/2)
                    gSlide_Info[i].Ys = PICINFO[0].y + PICINFO[2].h/2;
                if(PICINFO[0].y + PICINFO[0].h - gSlide_Info[i].Ye < PICINFO[2].h/2)
                    gSlide_Info[i].Ye = PICINFO[0].y + PICINFO[0].h - PICINFO[2].h/2;
            }
        }
    }
    else
    {

        // Coordinate calculation
        if (gSlide_Info[i].direction == 0 || gSlide_Info[i].direction == 1)
        {
            PICINFO[0].w = PICINFO[1].w; // max w
            PICINFO[0].x = PICINFO[1].x;
            PICINFO[1].x = 0;
            if (PICINFO[2].h < PICINFO[1].h)
            {
                PICINFO[0].h = PICINFO[1].h;
                PICINFO[0].y = PICINFO[1].y;
                PICINFO[1].y = 0;
                PICINFO[2].y = (PICINFO[1].h - PICINFO[2].h) / 2;
            }
            else
            {
                PICINFO[0].h = PICINFO[2].h;
                PICINFO[0].y = PICINFO[1].y - (PICINFO[2].h - PICINFO[1].h) / 2;
                PICINFO[1].y = (PICINFO[2].h - PICINFO[1].h) / 2;
                PICINFO[2].y = 0;
            }
            if (gSlide_Info[i].arrowid != 0xFFFF)
            {
                if(gSlide_Info[i].Xs - PICINFO[0].x < PICINFO[2].w/2)
                    gSlide_Info[i].Xs = PICINFO[0].x + PICINFO[2].w/2;
                if(PICINFO[0].x + PICINFO[0].w - gSlide_Info[i].Xe < PICINFO[2].w/2)
                    gSlide_Info[i].Xe = PICINFO[0].x + PICINFO[0].w - PICINFO[2].w/2;
            }
        }
        else if (gSlide_Info[i].direction == 2 || gSlide_Info[i].direction == 3)
        {
            PICINFO[0].h = PICINFO[1].h;
            PICINFO[0].y = PICINFO[1].y;
            PICINFO[1].y = 0;
            if (PICINFO[2].w < PICINFO[1].w)
            {
                PICINFO[0].w = PICINFO[1].w;
                PICINFO[0].x = gSlide_Info[i].x2;
                PICINFO[1].x = 0;
                PICINFO[2].x = (PICINFO[1].w - PICINFO[2].w) / 2;
            }
            else
            {
                PICINFO[0].w = PICINFO[2].w;
                PICINFO[0].x = gSlide_Info[i].x2 - (PICINFO[2].w - PICINFO[1].w) / 2;
                PICINFO[1].x = (PICINFO[2].w - PICINFO[1].w) / 2;
                PICINFO[2].x = 0;
            }
            if (gSlide_Info[i].arrowid != 0xFFFF)
            {
                if(gSlide_Info[i].Ys - PICINFO[0].y < PICINFO[2].h/2)
                    gSlide_Info[i].Ys = PICINFO[0].y + PICINFO[2].h/2;
                if(PICINFO[0].y + PICINFO[0].h - gSlide_Info[i].Ye < PICINFO[2].h/2)
                    gSlide_Info[i].Ye = PICINFO[0].y + PICINFO[0].h - PICINFO[2].h/2;
            }
        }

        // full-screen background
//        if(PICINFO[1].flag == 1 || PICINFO[1].flag == 2)
//        LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
//                            PICINFO[0].x, PICINFO[0].y, LCD_XSIZE_TFT, FullScreen_addr,
//                            PICINFO[0].w, PICINFO[0].h, FullScreen_flag);
        LT268_BG_to_buffer(0, 0, PICINFO[0].w, m_PngData,
                            PICINFO[0].x, PICINFO[0].y, PICINFO[0].w, PICINFO[0].h);
    }

    switch (gSlide_Info[i].direction)
    {
        case 0: // From left to right
//			if (Slide_flag == 0)
//			{
                sum = (var[gSlide_Info[i].p_add * 2] << 8) + var[gSlide_Info[i].p_add * 2 + 1];
                if (sum > gSlide_Info[i].V_max)
                    sum = gSlide_Info[i].V_max;
                else if (sum < gSlide_Info[i].V_min)
                    sum = gSlide_Info[i].V_min;

                w = PICINFO[1].w * (sum - gSlide_Info[i].V_min) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);
//			}
//			else
//				w = gSlide_Info[i].dx - gSlide_Info[i].Xs;

            // progress bar
            LT268_pic_to_buffer(PICINFO[1].x, PICINFO[1].y, PICINFO[0].w, m_PngData,
                                0, 0, PICINFO[1].w, PICINFO[1].addr,
                                w, PICINFO[1].h, PICINFO[1].flag);

            if (gSlide_Info[i].arrowid != 0xFFFF)
            {
                w = (gSlide_Info[i].Xe - gSlide_Info[i].Xs) * (sum - gSlide_Info[i].V_min) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);

                LT268_pic_to_buffer(gSlide_Info[i].Xs - PICINFO[0].x + w - PICINFO[2].w / 2, PICINFO[2].y, PICINFO[0].w, m_PngData,
                                    0, 0, PICINFO[2].w, PICINFO[2].addr,
                                    PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
            }

            break;
        case 1: // From right to left
//			if (Slide_flag == 0)
//			{
                sum = (var[gSlide_Info[i].p_add * 2] << 8) + var[gSlide_Info[i].p_add * 2 + 1];
                if (sum > gSlide_Info[i].V_max)
                    sum = gSlide_Info[i].V_max;
                else if (sum < gSlide_Info[i].V_min)
                    sum = gSlide_Info[i].V_min;

                w = PICINFO[1].w * (sum - gSlide_Info[i].V_min) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);
//			}

            // progress bar
            LT268_pic_to_buffer(PICINFO[1].x + PICINFO[1].w - w, PICINFO[1].y, PICINFO[0].w, m_PngData,
                                PICINFO[1].w - w, 0, PICINFO[1].w, PICINFO[1].addr,
                                w, PICINFO[1].h, PICINFO[1].flag);

            if (gSlide_Info[i].arrowid != 0xFFFF)
            {
                w = (gSlide_Info[i].Xe - gSlide_Info[i].Xs) * (sum - gSlide_Info[i].V_min) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);

                LT268_pic_to_buffer(gSlide_Info[i].Xe - PICINFO[0].x - w - PICINFO[2].w / 2, PICINFO[2].y, PICINFO[0].w, m_PngData,
                                    0, 0, PICINFO[2].w, PICINFO[2].addr,
                                    PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
            }

            break;
        case 2: // From top to bottom
//			if (Slide_flag == 0)
//			{
                sum = (var[gSlide_Info[i].p_add * 2] << 8) + var[gSlide_Info[i].p_add * 2 + 1];
                if (sum > gSlide_Info[i].V_max)
                    sum = gSlide_Info[i].V_max;
                else if (sum < gSlide_Info[i].V_min)
                    sum = gSlide_Info[i].V_min;

                h = PICINFO[1].h * (sum - gSlide_Info[i].V_min) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);
//			}
//			else
//			{
//				h = gSlide_Info[i].dy - gSlide_Info[i].Ys;
//			}

            LT268_pic_to_buffer(PICINFO[1].x, PICINFO[1].y, PICINFO[0].w, m_PngData,
                                0, 0, PICINFO[1].w, PICINFO[1].addr,
                                PICINFO[1].w, h, PICINFO[1].flag);

            // touch icon
            if (gSlide_Info[i].arrowid != 0xFFFF)
            {
                h = (gSlide_Info[i].Ye - gSlide_Info[i].Ys) * (sum - gSlide_Info[i].V_min) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);

                LT268_pic_to_buffer(PICINFO[2].x, gSlide_Info[i].Ys - PICINFO[0].y + h - PICINFO[2].h / 2, PICINFO[0].w, m_PngData,
                                    0, 0, PICINFO[2].w, PICINFO[2].addr,
                                    PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
            }

            break;
        case 3: // From bottom to top
//			if (Slide_flag == 0)
//			{
                sum = (var[gSlide_Info[i].p_add * 2] << 8) + var[gSlide_Info[i].p_add * 2 + 1];
                if (sum > gSlide_Info[i].V_max)
                    sum = gSlide_Info[i].V_max;
                else if (sum < gSlide_Info[i].V_min)
                    sum = gSlide_Info[i].V_min;

                h = PICINFO[1].h * (sum - gSlide_Info[i].V_min) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);
//			}
//			else
//			{
//				h = gSlide_Info[i].Ye - gSlide_Info[i].dy;
//			}

            // progress bar
            LT268_pic_to_buffer(PICINFO[1].x, PICINFO[1].y + PICINFO[1].h - h, PICINFO[0].w, m_PngData,
                                0, PICINFO[1].h - h, PICINFO[1].w, PICINFO[1].addr,
                                PICINFO[1].w, h, PICINFO[1].flag);

            if (gSlide_Info[i].arrowid != 0xFFFF)
            {
                h = (gSlide_Info[i].Ye - gSlide_Info[i].Ys) * (sum - gSlide_Info[i].V_min) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);

                LT268_pic_to_buffer(PICINFO[2].x, gSlide_Info[i].Ye - PICINFO[0].y - h - PICINFO[2].h / 2, PICINFO[0].w, m_PngData,
                                    0, 0, PICINFO[2].w, PICINFO[2].addr,
                                    PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
            }

            break;
        default:
            break;
    }

    // display
    LT268_buffer_to_TFT(0, 0, PICINFO[0].w, m_PngData,
                        PICINFO[0].x, PICINFO[0].y, PICINFO[0].w, PICINFO[0].h);

}

/***********************************************************************************
 * Function Name : Progress_bar_sliding
 * Description   : Touch detection of sliding progress bar.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Progress_bar_sliding(void)
{
    uint8_t i = 0, rebuf[20];
    int16_t temp;
    int32_t sum = 0;
    float step = 0;
    if (gTpInfo.sta)
    {
        for (i = 0; i < Slide_count; i++)
        {
            if (gSlide_Info[i].lastx != gTpInfo.x[0] || gSlide_Info[i].lasty != gTpInfo.y[0])
            {
                switch (gSlide_Info[i].direction)
                {
                case 0: // From left to right
                    if (gTpInfo.x[0] >= gSlide_Info[i].Xs - 40 && gTpInfo.y[0] >= gSlide_Info[i].Ys &&
                            gTpInfo.x[0] <= gSlide_Info[i].Xe + 40 && gTpInfo.y[0] <= gSlide_Info[i].Ye &&
                            ((slide_first_touch == 0 && button_Press_flag == 0) || (slide_first_touch == 1 && slide_num == i)))
                    {
                        if (slide_first_touch == 0)
                        {
                            slide_first_touch = 1;
                            if (buzzer)
                                touch_buzzer();
                        }
                        slide_num = i;
                        button_Press_flag = 1;

                        gSlide_Info[i].dx = gTpInfo.x[0];
                        if (gTpInfo.x[0] > gSlide_Info[i].Xe)
                            gSlide_Info[i].dx = gSlide_Info[i].Xe;
                        else if (gTpInfo.x[0] < gSlide_Info[i].Xs)
                            gSlide_Info[i].dx = gSlide_Info[i].Xs;

                        step = ((float)(gSlide_Info[i].V_max - gSlide_Info[i].V_min) / (float)(gSlide_Info[i].Xe - gSlide_Info[i].Xs));
                        if (gSlide_Info[i].dx == gSlide_Info[i].Xs)
                        {
                            var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_min >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_min & 0xff;
                        }
                        else if (gSlide_Info[i].dx == gSlide_Info[i].Xe)
                        {
                            var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_max >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_max & 0xff;
                        }
                        else
                        {
                            temp = (gSlide_Info[i].dx - gSlide_Info[i].Xs) * step + gSlide_Info[i].V_min;
                            var[gSlide_Info[i].p_add * 2] = temp >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = temp & 0xff;
                        }
                        gSlide_Info[i].lasty = gTpInfo.y[0];
                        if (gSlide_Info[i].lastx != gTpInfo.x[0])
                        {
                            gSlide_Info[i].lastx = gTpInfo.x[0];
                            Slide_flag = 1;
                        }
                    }
                    break;
                case 1: // From right to left
                    if (gTpInfo.x[0] >= gSlide_Info[i].Xs - 40 && gTpInfo.y[0] >= gSlide_Info[i].Ys &&
                            gTpInfo.x[0] <= gSlide_Info[i].Xe + 40 && gTpInfo.y[0] <= gSlide_Info[i].Ye &&
                            ((slide_first_touch == 0 && button_Press_flag == 0) || (slide_first_touch == 1 && slide_num == i)))
                    {
                        if (slide_first_touch == 0)
                        {
                            slide_first_touch = 1;
                            if (buzzer)
                                touch_buzzer();
                        }
                        slide_num = i;
                        button_Press_flag = 1;
                        gSlide_Info[i].dx = gTpInfo.x[0];
                        if (gTpInfo.x[0] > gSlide_Info[i].Xe)
                            gSlide_Info[i].dx = gSlide_Info[i].Xe;
                        else if (gTpInfo.x[0] < gSlide_Info[i].Xs)
                            gSlide_Info[i].dx = gSlide_Info[i].Xs;

                        step = ((float)(gSlide_Info[i].V_max - gSlide_Info[i].V_min) / (float)(gSlide_Info[i].Xe - gSlide_Info[i].Xs));
                        if (gSlide_Info[i].dx == gSlide_Info[i].Xs)
                        {
                            var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_max >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_max & 0xff;
                        }
                        else if (gSlide_Info[i].dx == gSlide_Info[i].Xe)
                        {
                            var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_min >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_min & 0xff;
                        }
                        else
                        {
                            temp = (gSlide_Info[i].Xe - gSlide_Info[i].dx) * step + gSlide_Info[i].V_min;
                            var[gSlide_Info[i].p_add * 2] = temp >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = temp & 0xff;
                        }
                        gSlide_Info[i].lasty = gTpInfo.y[0];
                        if (gSlide_Info[i].lastx != gTpInfo.x[0])
                        {
                            gSlide_Info[i].lastx = gTpInfo.x[0];
                            Slide_flag = 1;
                        }
                    }
                    break;
                case 2: // From top to bottom
                    if (gTpInfo.x[0] >= gSlide_Info[i].Xs && gTpInfo.y[0] >= gSlide_Info[i].Ys - 40 &&
                            gTpInfo.x[0] <= gSlide_Info[i].Xe && gTpInfo.y[0] <= gSlide_Info[i].Ye + 40 &&
                            ((slide_first_touch == 0 && button_Press_flag == 0) || (slide_first_touch == 1 && slide_num == i)))
                    {
                        if (slide_first_touch == 0)
                        {
                            slide_first_touch = 1;
                            if (buzzer)
                                touch_buzzer();
                        }
                        slide_num = i;
                        button_Press_flag = 1;
                        gSlide_Info[i].dy = gTpInfo.y[0];
                        if (gTpInfo.y[0] > gSlide_Info[i].Ye)
                            gSlide_Info[i].dy = gSlide_Info[i].Ye;
                        else if (gTpInfo.y[0] < gSlide_Info[i].Ys)
                            gSlide_Info[i].dy = gSlide_Info[i].Ys;

                        step = (float)((gSlide_Info[i].V_max - gSlide_Info[i].V_min) / (float)(gSlide_Info[i].Ye - gSlide_Info[i].Ys));
                        if (gSlide_Info[i].dy == gSlide_Info[i].Ys)
                        {
                            var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_min >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_min & 0xff;
                        }
                        else if (gSlide_Info[i].dy == gSlide_Info[i].Ye)
                        {
                            var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_max >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_max & 0xff;
                        }
                        else
                        {
                            temp = (gSlide_Info[i].dy - gSlide_Info[i].Ys) * step + gSlide_Info[i].V_min;
                            var[gSlide_Info[i].p_add * 2] = temp >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = temp & 0xff;
                        }

                        gSlide_Info[i].lastx = gTpInfo.x[0];
                        if (gSlide_Info[i].lasty != gTpInfo.y[0])
                        {
                            gSlide_Info[i].lasty = gTpInfo.y[0];
                            Slide_flag = 1;
                        }
                    }
                    break;
                case 3: // From bottom to top
                    if (gTpInfo.x[0] >= gSlide_Info[i].Xs && gTpInfo.y[0] >= gSlide_Info[i].Ys - 40 &&
                            gTpInfo.x[0] <= gSlide_Info[i].Xe && gTpInfo.y[0] <= gSlide_Info[i].Ye + 40 &&
                            ((slide_first_touch == 0 && button_Press_flag == 0) || (slide_first_touch == 1 && slide_num == i)))
                    {
                        if (slide_first_touch == 0)
                        {
                            slide_first_touch = 1;
                            if (buzzer)
                                touch_buzzer();
                        }
                        slide_num = i;
                        button_Press_flag = 1;
                        gSlide_Info[i].dy = gTpInfo.y[0];
                        if (gTpInfo.y[0] > gSlide_Info[i].Ye)
                            gSlide_Info[i].dy = gSlide_Info[i].Ye;
                        else if (gTpInfo.y[0] < gSlide_Info[i].Ys)
                            gSlide_Info[i].dy = gSlide_Info[i].Ys;

                        step = (float)((gSlide_Info[i].V_max - gSlide_Info[i].V_min) / (float)(gSlide_Info[i].Ye - gSlide_Info[i].Ys));
                        if (gSlide_Info[i].dy == gSlide_Info[i].Ys)
                        {
                            var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_max >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_max & 0xff;
                        }
                        else if (gSlide_Info[i].dy == gSlide_Info[i].Ye)
                        {
                            var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_min >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_min & 0xff;
                        }
                        else
                        {
                            temp = (gSlide_Info[i].Ye - gSlide_Info[i].dy) * step + gSlide_Info[i].V_min;
                            var[gSlide_Info[i].p_add * 2] = temp >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = temp & 0xff;
                        }
                        gSlide_Info[i].lastx = gTpInfo.x[0];
                        if (gSlide_Info[i].lasty != gTpInfo.y[0])
                        {
                            gSlide_Info[i].lasty = gTpInfo.y[0];
                            Slide_flag = 1;
                        }
                    }
                    break;
                default:
                    break;
                }
                if (Slide_flag == 1)
                {
                    if (gSlide_Info[i].p_add >= VAR_ADDR_S)
                        reg_operation(gSlide_Info[i].p_add);

                    page_date_update(pic_id);
                    Disp_slide(i);
                    Slide_flag = 0;
                }
            }
        }
    }
    else if (slide_first_touch == 1)
    {
        slide_first_touch = 0;
        button_Press_flag = 0;
        if (gSlide_Info[slide_num].Code == 0xC004)
        {
            rebuf[3] = 0x41;
            rebuf[4] = gSlide_Info[slide_num].p_add >> 8;
            rebuf[5] = gSlide_Info[slide_num].p_add & 0xFF;
            rebuf[6] = var[gSlide_Info[slide_num].p_add * 2];
            rebuf[7] = var[gSlide_Info[slide_num].p_add * 2 + 1];
            LT_InfoFeedback_with_addr(rebuf, 5);
        }
    }
}
RingSld_Info gRingSld_Info[RINGSLD_SIZE];
uint8_t RingSld_count = 0;
uint8_t RingSld_firsttouch = 0;
uint8_t RingSld_firstnum = 0;
/***********************************************************************************
 * Function Name : DL_RingSld
 * Description   : calculation for ring progress bar.
 * Input         : - num: which number of ring progress bar
 * Output        : None
 * Return        : None
 ************************************************************************************/
void DL_RingSld(uint8_t num)
{
	uint8_t buff[12] = {0};

	LT_ReadFlash_UI(buff, addr_index[10] + 12 * gRingSld_Info[num].frontID + multi_language * 12 * addr_index[11], 12);
	gRingSld_Info[num].w1 = buff[4] + (buff[5] << 8);
	gRingSld_Info[num].h1 = buff[6] + (buff[7] << 8);
	gRingSld_Info[num].xR = gRingSld_Info[num].x + gRingSld_Info[num].w1 / 2;
	gRingSld_Info[num].yR = gRingSld_Info[num].y + gRingSld_Info[num].h1 / 2;
}

void RingSld_Display(uint8_t num, uint16_t angle)
{
	uint8_t n = 0, flag = 0, i = 0, kk = 0, Symbol = 0;
	uint8_t buff1[12] = {0};
	uint16_t num_w, dot_w, h, canvas_numw, canvas_dotw;
	uint16_t xd = 0, dx = 0, dy = 0;
	int16_t temp ,value1 = 0;
	int32_t value = 0, ll;
	uint32_t zk_addr;
	uint16_t ring_R, ring_CX, ring_CY; // circular radius,centre point
	int32_t hh;

	// BG
	if (gRingSld_Info[num].bgID <= addr_index[11])
	{
		LT_ReadFlash_UI(buff1, addr_index[10] + 12 * gRingSld_Info[num].bgID + multi_language * 12 * addr_index[11], 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		if(pic_flag == ColorARGB0565 || pic_flag == ColorARGB4444 || pic_flag == ColorARGB8565)
		LT268_BG_to_buffer(0,0,pic_w,m_PngData,
				gRingSld_Info[num].x, gRingSld_Info[num].y,pic_w, pic_h);

		if (pic_len != 0 && pic_flag != 0xFF)
		{
			LT268_pic_to_buffer(0, 0, pic_w, m_PngData,
								0, 0, pic_w, pic_add,
								pic_w, pic_h, pic_flag);
		}

		LT_ReadFlash_UI(buff1, addr_index[10] + 12 * gRingSld_Info[num].frontID + multi_language * 12 * addr_index[11], 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		gRingSld_Info[num].w1 = pic_w;
		gRingSld_Info[num].h1 = pic_h;
		gRingSld_Info[num].rm1 = pic_flag;

	}
	else  //  BG == fullscreen
	{
		if(gRingSld_Info[num].frontID <= addr_index[11])
		{
			LT_ReadFlash_UI(buff1, addr_index[10] + 12 * gRingSld_Info[num].frontID + multi_language * 12 * addr_index[11], 12);
			pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
			pic_w = buff1[4] + (buff1[5] << 8);
			pic_h = buff1[6] + (buff1[7] << 8);
			pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
			pic_flag = buff1[11];

			gRingSld_Info[num].w1 = pic_w;
			gRingSld_Info[num].h1 = pic_h;
			gRingSld_Info[num].rm1 = pic_flag;


			if(pic_flag == ColorARGB0565 || pic_flag == ColorARGB4444 || pic_flag == ColorARGB8565)
				LT268_BG_to_buffer(0,0,pic_w,m_PngData,
						gRingSld_Info[num].x, gRingSld_Info[num].y,pic_w, pic_h);

		}
		else  return;
	}


	if (gRingSld_Info[num].arrowid != 0xFFFF)
	{
		LT_ReadFlash_UI(buff1, addr_index[10] + 12 * gRingSld_Info[num].arrowid, 12);
		PICINFO[2].addr = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		PICINFO[2].w = buff1[4] + (buff1[5] << 8);
		PICINFO[2].h = buff1[6] + (buff1[7] << 8);
		PICINFO[2].flag = buff1[11];

		gRingSld_Info[num].w2 = PICINFO[2].w - 1; //��ֹ��ͼΪż����ring_CX-w2/2���
		gRingSld_Info[num].h2 = PICINFO[2].h - 1;
	}

	if (pic_w % 2)
	{
		ring_R = pic_w / 2 + 1;
		ring_CX = pic_w / 2;
		ring_CY = pic_w / 2;
	}
	else
	{
		ring_R = pic_w / 2;
		ring_CX = pic_w / 2 - 1;
		ring_CY = pic_w / 2 - 1;
	}

	//���м����ȡ
	if((angle>0)&&(angle<=90))
	{
//		if(angle!=90)
			for (uint16_t yy = ring_CY; yy < pic_h; yy++)
			{
				hh=ring_CX-(yy-ring_CY)*FastTan(angle)/MAGNIFICATION;

//				if(hh<0)
//					break;
				LT_ReadFlash_DMA_UI(DMA_rxbuf1, pic_add+pic_w*yy*2, ring_R*2);
				for (uint16_t xx = 0; xx < ring_R; xx++)
				{
					if(xx>hh)
						LT268_buffer_pixel_blending(&p16_m_PngData[pic_w*yy + xx], &p16_DMA_rxbuf1[xx], pic_flag);
				}
			}
	}
	else if((angle>90)&&(angle<=180))
	{
		LT268_pic_to_buffer(0, ring_CY, pic_w, m_PngData,
				0, ring_CY, pic_w, pic_add,
				ring_R, pic_h-ring_CY, pic_flag);

		for (uint16_t yy = 0; yy < ring_R; yy++)
		{
			hh=ring_CX-(ring_CY-yy)*MAGNIFICATION/FastTan(angle-90);

				if(hh>ring_R)
					break;
			LT_ReadFlash_DMA_UI(DMA_rxbuf1, pic_add+pic_w*yy*2, ring_R*2);
			for (uint16_t xx = 0; xx < ring_R; xx++)
			{
				if(xx<hh)
					LT268_buffer_pixel_blending(&p16_m_PngData[pic_w*yy + xx], &p16_DMA_rxbuf1[xx], pic_flag);
			}
		}
	}
	else if((angle>180)&&(angle<=270))
	{
		LT268_pic_to_buffer(0, 0, pic_w, m_PngData,
				0, 0, pic_w, pic_add,
				ring_R, pic_h, pic_flag);

		for (uint16_t yy = 0; yy < ring_R; yy++)
		{
			hh=(ring_CY-yy)*FastTan(angle-180)/MAGNIFICATION;

//			if(hh>ring_R)
//				break;
			LT_ReadFlash_DMA_UI(DMA_rxbuf1, pic_add+pic_w*yy*2+ring_CX*2, ring_R*2);
			for (uint16_t xx = 0; xx < ring_R; xx++)
			{
				if(xx<hh)
					LT268_buffer_pixel_blending(&p16_m_PngData[pic_w*yy+ring_CX + xx], &p16_DMA_rxbuf1[xx], pic_flag);
			}
		}
	}
	else if((angle>270)&&(angle<=360))
	{
		LT268_pic_to_buffer(0, 0, pic_w, m_PngData,
				0, 0, pic_w, pic_add,
				pic_w, ring_R, pic_flag);
		LT268_pic_to_buffer(0, ring_CY, pic_w, m_PngData,
				0, ring_CY, pic_w, pic_add,
				ring_R, pic_h-ring_CY, pic_flag);

		for (uint16_t yy = ring_CY; yy < pic_h; yy++)
		{
			hh=(yy-ring_CY)*MAGNIFICATION/FastTan(angle-270);

//			if(hh>ring_R)
//				break;
			LT_ReadFlash_DMA_UI(DMA_rxbuf1, pic_add+pic_w*yy*2+(ring_CX+1)*2, ring_R*2);
			for (uint16_t xx = 0; xx < ring_R; xx++)
			{
				if(xx>=hh)
					LT268_buffer_pixel_blending(&p16_m_PngData[pic_w*yy+(ring_CX+1) + xx], &p16_DMA_rxbuf1[xx], pic_flag);
			}
		}
	 }

	//touch icon
	gRingSld_Info[num].x2 = ring_CX - gRingSld_Info[num].Sld_R * fast_sin(angle)/MULTIPLE - gRingSld_Info[num].w2 / 2;
	gRingSld_Info[num].y2 = ring_CY + gRingSld_Info[num].Sld_R * fast_cos(angle)/MULTIPLE - gRingSld_Info[num].h2 / 2;
	if (gRingSld_Info[num].arrowid != 0xFFFF)
	{
		LT268_pic_to_buffer(gRingSld_Info[num].x2, gRingSld_Info[num].y2, gRingSld_Info[num].w1, m_PngData,
							0, 0, PICINFO[2].w, PICINFO[2].addr,
							PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
	}

	if (gRingSld_Info[num].flag == 1)
	{
		memset(Display_buff, 0, 20);
		LT_ReadFlash_UI(buff1, addr_index[2] + gRingSld_Info[num].zk_id * 8, 4);
		zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		value1 = (var[gRingSld_Info[num].p_add * 2] << 8) + var[gRingSld_Info[num].p_add * 2 + 1];
		ll = pow(10, gRingSld_Info[num].I_num + gRingSld_Info[num].D_num);
		value = value1 % ll;
		if (value1 < 0)
		{
			Display_buff[Symbol] = '-';
			Symbol = 1;
			value = ~value1 + 1;
		}
		ll = value;
		do
		{ // Get the number of digits
			n++;
			ll /= 10;
		} while (ll > 0);

		// With decimal point
		if (gRingSld_Info[num].D_num > 0)
		{
			if (gRingSld_Info[num].D_num >= n)
			{
				Display_buff[Symbol] = '0';
				Display_buff[Symbol + 1] = '.';
				for (i = n; gRingSld_Info[num].D_num > i; i++)
				{
					Display_buff[Symbol + 2 + i - n] = '0';
				}

				sprintf(&Display_buff[Symbol + 2 + gRingSld_Info[num].D_num - n], "%d", value);


			}
			else
			{
				sprintf(&Display_buff[Symbol], "%d", value);

				for (i = 0; i < gRingSld_Info[num].D_num; i++)
				{
					Display_buff[n + Symbol - i] = Display_buff[n - 1 + Symbol - i];
				}

				Display_buff[n + Symbol - gRingSld_Info[num].D_num] = '.';

			}
		}
		else
		{
			sprintf(&Display_buff[Symbol], "%d", value);
		}

		LT_ReadFlash_UI(buff1, zk_addr, 4);

		LT_Print_zk_Font_BUFF(4, zk_addr,
							  LAY_BUFF1, LCD_XSIZE_TFT, buff1[2], buff1[3], gRingSld_Info[num].Alig, gRingSld_Info[num].color, Black, 0,
							  gRingSld_Info[num].w1, gRingSld_Info[num].h1, m_PngData, gRingSld_Info[num].dx - gRingSld_Info[num].x, gRingSld_Info[num].dy - gRingSld_Info[num].y,
							  0, 0, Display_buff, sizeof(Display_buff));
	}
	else if (gRingSld_Info[num].flag == 2)
	{
		memset(Display_buff, 0, 20);
		value1 = (var[gRingSld_Info[num].p_add * 2] << 8) + var[gRingSld_Info[num].p_add * 2 + 1];

		if (value1 < 0)
		{
			Display_buff[kk] = 11;
			kk++;
			value = ~value1 + 1;
		}
		else
		{
			value = value1;
		}
		value = value % ((int)pow(10, gRingSld_Info[num].I_num + gRingSld_Info[num].D_num));

		for (i = 0; i < gRingSld_Info[num].I_num; i++) // All integers
		{

			Display_buff[kk] = value / (int)pow(10, gRingSld_Info[num].I_num - i - 1 + gRingSld_Info[num].D_num);

			if (Display_buff[kk] != 0 || flag == 1)
			{
				kk++;
				flag = 1; // The first place is not 0
			}
			value = value % (int)pow(10, gRingSld_Info[num].I_num - i - 1 + gRingSld_Info[num].D_num);
		}

		if (gRingSld_Info[num].D_num > 0)
		{
			if (flag == 0)
			{
				Display_buff[kk] = 0; //"."
				kk++;
			}
			Display_buff[kk] = 10; //"."
			kk++;
		}
		else
		{
			if (flag == 0)
			{
				Display_buff[kk] = 0; //"."
				kk++;
			}
		}
		for (i = 0; i < gRingSld_Info[num].D_num; i++) // Decimal
		{
			Display_buff[kk] = value / (int)pow(10, gRingSld_Info[num].D_num - i - 1);
			kk++;
			value = value % (int)pow(10, i - 1 + gRingSld_Info[num].D_num);
		}

        xd = 0;
        for (i = 0; i < kk; i++)
        {
            if (gRingSld_Info[num].s_id + Display_buff[i] >= addr_index[11]) continue; // ICON is available
            LT_ReadFlash_UI(buff1, addr_index[10] + 12 * (gRingSld_Info[num].s_id + Display_buff[i]) + multi_language * 12 * addr_index[11], 12);
            num_w = buff1[4] + (buff1[5] << 8);
            xd += num_w;
        }
		
		if (gRingSld_Info[num].Alig == 0)
			dx = gRingSld_Info[num].dx - gRingSld_Info[num].x;
		else if (gRingSld_Info[num].Alig == 1)
			dx = gRingSld_Info[num].dx - gRingSld_Info[num].x - xd / 2;
		else if (gRingSld_Info[num].Alig == 2)
			dx = gRingSld_Info[num].dx - gRingSld_Info[num].x - xd + 1;

		dy = gRingSld_Info[num].dy - gRingSld_Info[num].y;

        // buffer picture
        for (i = 0; i < kk; i++)
        {
            if (gRingSld_Info[num].s_id + Display_buff[i] >= addr_index[11])
                continue; // ICON is available
            LT_ReadFlash_UI(buff1, addr_index[10] + 12 * (gRingSld_Info[num].s_id + Display_buff[i]) + multi_language * 12 * addr_index[11], 12);
            PICINFO[0].addr = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
            PICINFO[0].w = buff1[4] + (buff1[5] << 8);
            PICINFO[0].h = buff1[6] + (buff1[7] << 8);
            PICINFO[0].len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
            PICINFO[0].flag = buff1[11];
            LT268_pic_to_buffer(dx, dy, pic_w, m_PngData,
                                0, 0, PICINFO[0].w, PICINFO[0].addr,
								PICINFO[0].w, PICINFO[0].h, PICINFO[0].flag);
            dx += PICINFO[0].w;
        }
	}

	LT268_buffer_to_TFT(0, 0, pic_w, m_PngData,
						gRingSld_Info[num].x, gRingSld_Info[num].y, pic_w, pic_h);
}

/***********************************************************************************
 * Function Name : RingSld_touch
 * Description   : Touch detection of ring progress bar.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void RingSld_touch(void)
{

	uint8_t i;
	uint8_t rebuf[20];
	uint16_t angle = 0, j = 0, V = 0;
	int32_t x1, y1, x2, y2;
	float Xa, Ya, Xb, Yb, Xc, Yc = 0;

	if (gTpInfo.sta)
	{
		for (i = 0; i < RingSld_count; i++)
		{
			if(lastx != gTpInfo.x[0] || lasty != gTpInfo.y[0])
			{
				x1 = gTpInfo.x[0] - gRingSld_Info[i].xR;
				y1 = gTpInfo.y[0] - gRingSld_Info[i].yR;
				
				if (x1 * x1 + y1 * y1 >= (gRingSld_Info[i].Sld_R - gRingSld_Info[i].tp_R) * (gRingSld_Info[i].Sld_R - gRingSld_Info[i].tp_R) &&
					x1 * x1 + y1 * y1 <= (gRingSld_Info[i].Sld_R + gRingSld_Info[i].tp_R) * (gRingSld_Info[i].Sld_R + gRingSld_Info[i].tp_R) &&
					((RingSld_firsttouch == 0 && button_Press_flag == 0) || (RingSld_firsttouch == 1 && RingSld_firstnum == i)))
				{
					
					lastx = gTpInfo.x[0];
					lasty = gTpInfo.y[0];
					
					if (RingSld_firsttouch == 0 || RingSld_firstnum != i)
					{
						if (buzzer)
							touch_buzzer();
						button_Press_flag = 1;
						RingSld_firsttouch = 1;
						RingSld_firstnum = i;
						DL_RingSld(i);
					}
					// 180 to 270 degrees
					if (gTpInfo.x[0] >= gRingSld_Info[i].xR &&
						gTpInfo.x[0] <= gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R + gRingSld_Info[i].tp_R &&
						gTpInfo.y[0] >= gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R - gRingSld_Info[i].tp_R &&
						gTpInfo.y[0] <= gRingSld_Info[i].yR)
					{
						if (gTpInfo.x[0] == (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(0)/MULTIPLE) ||
							gTpInfo.x[0] - 1 == (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(0)/MULTIPLE))
						{
							angle = 180;
						}
						else if (gTpInfo.y[0] == (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(90)/MULTIPLE) ||
								 gTpInfo.y[0] + 1 == (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(90)/MULTIPLE))
						{
							angle = 270;
						}
						else
						{
							for (j = 1; j < 90; j++)
							{
								Xa = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j - 1)/MULTIPLE);
								Ya = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j - 1)/MULTIPLE);
								Xb = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j)/MULTIPLE);
								Yb = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j)/MULTIPLE);
								Xc = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j + 1)/MULTIPLE);
								Yc = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j + 1)/MULTIPLE);
								if (Xb * Xb + Yb * Yb <= Xa * Xa + Ya * Ya && Xb * Xb + Yb * Yb <= Xc * Xc + Yc * Yc)
								{
									angle = j + 180;
									break;
								}
							}
						}
					}
					// 270 to 360 degrees
					else if (gTpInfo.x[0] >= gRingSld_Info[i].xR && gTpInfo.x[0] <= gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R + gRingSld_Info[i].tp_R &&
							 gTpInfo.y[0] >= gRingSld_Info[i].yR && gTpInfo.y[0] <= gRingSld_Info[i].yR + gRingSld_Info[i].Sld_R + gRingSld_Info[i].tp_R)
					{

						if (gTpInfo.x[0] == (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(180)/MULTIPLE))
						{
							angle = 0;
						}
						else if (gTpInfo.y[0] == (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(90)/MULTIPLE) ||
								 gTpInfo.y[0] - 1 == (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(90)/MULTIPLE))
						{
							angle = 270;
						}
						else
						{
							for (j = 91; j < 180; j++)
							{
								Xa = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j - 1)/MULTIPLE);
								Ya = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j - 1)/MULTIPLE);
								Xb = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j)/MULTIPLE);
								Yb = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j)/MULTIPLE);
								Xc = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j + 1)/MULTIPLE);
								Yc = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j + 1)/MULTIPLE);
								if (Xb * Xb + Yb * Yb <= Xa * Xa + Ya * Ya && Xb * Xb + Yb * Yb <= Xc * Xc + Yc * Yc)
								{
									angle = j + 180;
									break;
								}
							}
						}
					}
					// 0 to 90 degrees
					else if (gTpInfo.x[0] >= gRingSld_Info[i].xR - gRingSld_Info[i].Sld_R - gRingSld_Info[i].tp_R && gTpInfo.x[0] <= gRingSld_Info[i].xR &&
							 gTpInfo.y[0] >= gRingSld_Info[i].yR && gTpInfo.y[0] <= gRingSld_Info[i].yR + gRingSld_Info[i].Sld_R + gRingSld_Info[i].tp_R)
					{
						if (gTpInfo.x[0] == (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(180)/MULTIPLE))
						{
							angle = 0;
						}
						else if (gTpInfo.y[0] == (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(270)/MULTIPLE) ||
								 gTpInfo.y[0] - 1 == (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(270)/MULTIPLE))
						{
							angle = 90;
						}
						else
						{
							for (j = 181; j < 270; j++)
							{
								Xa = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j - 1)/MULTIPLE);
								Ya = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j - 1)/MULTIPLE);
								Xb = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j)/MULTIPLE);
								Yb = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j)/MULTIPLE);
								Xc = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j + 1)/MULTIPLE);
								Yc = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j + 1)/MULTIPLE);
								if (Xb * Xb + Yb * Yb <= Xa * Xa + Ya * Ya && Xb * Xb + Yb * Yb <= Xc * Xc + Yc * Yc)
								{
									angle = j - 180;
									break;
								}
							}
						}
					}
					// 90 to 180 degrees
					else if (gTpInfo.x[0] >= gRingSld_Info[i].xR - gRingSld_Info[i].Sld_R - gRingSld_Info[i].tp_R && gTpInfo.x[0] <= gRingSld_Info[i].xR && gTpInfo.y[0] >= gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R - gRingSld_Info[i].tp_R && gTpInfo.y[0] <= gRingSld_Info[i].yR)
					{
						if (gTpInfo.x[0] == (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(0)/MULTIPLE) ||
							gTpInfo.x[0] + 1 == (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(0)/MULTIPLE))
						{
							angle = 180;
						}
						else if (gTpInfo.y[0] == (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(270)/MULTIPLE) ||
								 gTpInfo.y[0] + 1 == (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(270)/MULTIPLE))
						{
							angle = 90;
						}
						else
						{
							for (j = 271; j < 360; j++)
							{
								Xa = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j - 1)/MULTIPLE);
								Ya = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j - 1)/MULTIPLE);
								Xb = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j)/MULTIPLE);
								Yb = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j)/MULTIPLE);
								Xc = gTpInfo.x[0] - (gRingSld_Info[i].xR + gRingSld_Info[i].Sld_R * fast_sin(j + 1)/MULTIPLE);
								Yc = gTpInfo.y[0] - (gRingSld_Info[i].yR - gRingSld_Info[i].Sld_R * fast_cos(j + 1)/MULTIPLE);
								if (Xb * Xb + Yb * Yb <= Xa * Xa + Ya * Ya && Xb * Xb + Yb * Yb <= Xc * Xc + Yc * Yc)
								{
									angle = j - 180;
									break;
								}
							}
						}
					}

					if (angle <= gRingSld_Info[i].Eangle && angle >= gRingSld_Info[i].Sangle)
					{

						V = (gRingSld_Info[i].Vmax - gRingSld_Info[i].Vmin) * (angle - gRingSld_Info[i].Sangle) / (gRingSld_Info[i].Eangle - gRingSld_Info[i].Sangle) + gRingSld_Info[i].Vmin;

						var[gRingSld_Info[i].p_add * 2] = (V >> 8) & 0xFF;
						var[gRingSld_Info[i].p_add * 2 + 1] = V & 0xFF;

						RingSld_Display(i, angle);

						if (gRingSld_Info[i].p_add >= VAR_ADDR_S)
						{
							reg_operation(gRingSld_Info[i].p_add);
						}
						page_date_update(pic_id);
					}
					else if (angle > gRingSld_Info[i].Eangle && angle < gRingSld_Info[i].Eangle + 10)
					{
						angle = gRingSld_Info[i].Eangle;
						V = (gRingSld_Info[i].Vmax - gRingSld_Info[i].Vmin) * (angle - gRingSld_Info[i].Sangle) / (gRingSld_Info[i].Eangle - gRingSld_Info[i].Sangle) + gRingSld_Info[i].Vmin;

						var[gRingSld_Info[i].p_add * 2] = (V >> 8) & 0xFF;
						var[gRingSld_Info[i].p_add * 2 + 1] = V & 0xFF;

						RingSld_Display(i, angle);

						if (gRingSld_Info[i].p_add >= VAR_ADDR_S)
						{
							reg_operation(gRingSld_Info[i].p_add);
						}
						page_date_update(pic_id);
					}
					else if (angle < gRingSld_Info[i].Sangle && angle + 10 > gRingSld_Info[i].Sangle)
					{
						angle = gRingSld_Info[i].Sangle;
						V = (gRingSld_Info[i].Vmax - gRingSld_Info[i].Vmin) * (angle - gRingSld_Info[i].Sangle) / (gRingSld_Info[i].Eangle - gRingSld_Info[i].Sangle) + gRingSld_Info[i].Vmin;

						var[gRingSld_Info[i].p_add * 2] = (V >> 8) & 0xFF;
						var[gRingSld_Info[i].p_add * 2 + 1] = V & 0xFF;

						RingSld_Display(i, angle);

						if (gRingSld_Info[i].p_add >= VAR_ADDR_S)
						{
							reg_operation(gRingSld_Info[i].p_add);
						}
						page_date_update(pic_id);
					}
				}
			}
		}
	}

	else if (RingSld_firsttouch == 1)
	{
		RingSld_firsttouch = 0;
		button_Press_flag = 0;
		if (gRingSld_Info[RingSld_firstnum].Code == 0xC007)
		{
			rebuf[3] = 0x41;
			rebuf[4] = gRingSld_Info[RingSld_firstnum].p_add >> 8;
			rebuf[5] = gRingSld_Info[RingSld_firstnum].p_add & 0xFF;
			rebuf[6] = var[gRingSld_Info[RingSld_firstnum].p_add * 2];
			rebuf[7] = var[gRingSld_Info[RingSld_firstnum].p_add * 2 + 1];
			LT_InfoFeedback_with_addr(rebuf, 5);
		}
	}

}

SldMenu_Info gSldMenu_Info[SLDMENU_SIZE];
//uint8_t SLDMfirsttouch = 0;
uint8_t sldmenu_count = 0, sldmenu_num = 0;
uint8_t sldmenu_flag = 0;
uint8_t sld_mum = 0;
uint8_t V_dev = 0;
uint16_t lastx = 0, lasty = 0, Sldw = 0, Sldh = 0;
uint16_t slide_wmax = 0;
/***********************************************************************************
 * Function Name : slideMune
 * Description   : Touch detection of slding menu.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void slideMune(void)
{
	uint8_t i = 0;
	uint8_t rebuf[20];
	uint16_t temp, sum, V=0;
	uint16_t dev = 0;
	int16_t df = 0;

	// press down
	if (gTpInfo.sta)
	{
		for (i = 0; i < sldmenu_count; i++)
		{

			if ((sldmenu_flag == 1) || (gTpInfo.x[0] >= gSldMenu_Info[i].Xs && gTpInfo.y[0] >= gSldMenu_Info[i].Ys && 
				gTpInfo.x[0] <= gSldMenu_Info[i].Xe && gTpInfo.y[0] <= gSldMenu_Info[i].Ye && button_Press_flag == 0 )  )
			{

				if (sldmenu_flag == 0) // First press
				{
					DL_menu(i);
					lastx = gTpInfo.x[0];
					lasty = gTpInfo.y[0];
					sldmenu_num = i;
					sldmenu_flag = 1;
					button_Press_flag = 1;
					if (buzzer)
						touch_buzzer();
					V_dev = 0;
				}
				else // Sliding treatment
				{
					if ((gSldMenu_Info[sldmenu_num].dir & 0x01) == 0) // up and down
					{
						df = lasty - gTpInfo.y[0];
						gSldMenu_Info[sldmenu_num].pos = gSldMenu_Info[sldmenu_num].pos + df;

						// if (gSldMenu_Info[sldmenu_num].p_add == (VAR_TIME + 2)) // day is special
						// {
						// 	if (var[(VAR_TIME + 1) * 2 + 1] == 1 || var[(VAR_TIME + 1) * 2 + 1] == 3 || var[(VAR_TIME + 1) * 2 + 1] == 5 ||
						// 		var[(VAR_TIME + 1) * 2 + 1] == 7 || var[(VAR_TIME + 1) * 2 + 1] == 8 || var[(VAR_TIME + 1) * 2 + 1] == 10 ||
						// 		var[(VAR_TIME + 1) * 2 + 1] == 12)
						// 	{
						// 		if (gSldMenu_Info[sldmenu_num].V_max > 31)
						// 			dev = (gSldMenu_Info[sldmenu_num].V_max - 31) * (gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2);
						// 		V_dev = 0;
						// 	}
						// 	else if (var[(VAR_TIME + 1) * 2 + 1] == 4 || var[(VAR_TIME + 1) * 2 + 1] == 6 || var[(VAR_TIME + 1) * 2 + 1] == 9 ||
						// 		var[(VAR_TIME + 1) * 2 + 1] == 11)
						// 	{
						// 		if (gSldMenu_Info[sldmenu_num].V_max > 30)
						// 			dev = (gSldMenu_Info[sldmenu_num].V_max - 30) * (gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2);
						// 		V_dev = 1;
						// 	}
						// 	else if (var[(VAR_TIME + 1) * 2 + 1] == 2)
						// 	{
						// 		if (Is_Leap_Year(var[(VAR_TIME + 0) * 2 + 1] + 2000)) // leap year
						// 		{
						// 			if (gSldMenu_Info[sldmenu_num].V_max > 29)
						// 				dev = (gSldMenu_Info[sldmenu_num].V_max - 29) * (gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2);
						// 			V_dev = 2;
						// 		}
						// 		else
						// 		{
						// 			if (gSldMenu_Info[sldmenu_num].V_max > 28)
						// 				dev = (gSldMenu_Info[sldmenu_num].V_max - 28) * (gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2);
						// 			V_dev = 3;
						// 		}
						// 	}
						// 	slide_wmax = (31 - V_dev) * (gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2);
						// }
						// else
						// 	slide_wmax = Sldh;

						if (gSldMenu_Info[sldmenu_num].dir == 0x80)
						{
							if (gSldMenu_Info[sldmenu_num].pos < 0)
								gSldMenu_Info[sldmenu_num].pos = 0;
							if (gSldMenu_Info[sldmenu_num].pos > (Sldh - dev - (gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2)))
								gSldMenu_Info[sldmenu_num].pos = Sldh - dev - (gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2);
						}
						else
						{
							if (gSldMenu_Info[sldmenu_num].pos < 0)
								gSldMenu_Info[sldmenu_num].pos = Sldh - dev + gSldMenu_Info[sldmenu_num].pos;
							if (gSldMenu_Info[sldmenu_num].pos > (Sldh - dev))
								gSldMenu_Info[sldmenu_num].pos = gSldMenu_Info[sldmenu_num].pos - (Sldh - dev);
						}
						if (df != 0)
						{
							dp_menu(sldmenu_num);
							lasty = gTpInfo.y[0];
						}
					}
					else if ((gSldMenu_Info[sldmenu_num].dir & 0x01) == 1) // the left and right
					{
						df = lastx - gTpInfo.x[0];
						gSldMenu_Info[sldmenu_num].pos = gSldMenu_Info[sldmenu_num].pos + df;

						if (gSldMenu_Info[sldmenu_num].dir == 0x81)
						{
							if (gSldMenu_Info[sldmenu_num].pos < 0)
								gSldMenu_Info[sldmenu_num].pos = 0; // in range
							if (gSldMenu_Info[sldmenu_num].pos > (Sldw - dev - (gSldMenu_Info[sldmenu_num].Xe - gSldMenu_Info[sldmenu_num].Xs - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2)))
								gSldMenu_Info[sldmenu_num].pos = Sldw - dev - (gSldMenu_Info[sldmenu_num].Xe - gSldMenu_Info[sldmenu_num].Xs - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2);
						}
						else
						{
							if (gSldMenu_Info[sldmenu_num].pos < 0)
								gSldMenu_Info[sldmenu_num].pos = Sldw - dev + gSldMenu_Info[sldmenu_num].pos; // in range
							if (gSldMenu_Info[sldmenu_num].pos > (Sldw - dev))
								gSldMenu_Info[sldmenu_num].pos = gSldMenu_Info[sldmenu_num].pos - (Sldw - dev);
						}
						if (df != 0)
						{
							dp_menu(sldmenu_num);
							lastx = gTpInfo.x[0];
						}
					}
				}
			}
		}
	}
	// raise
	else if (sldmenu_flag == 1 && (gTpInfo.sta == 0 ||
	 							   !(gTpInfo.x[0] >= gSldMenu_Info[sldmenu_num].Xs && gTpInfo.y[0] >= gSldMenu_Info[sldmenu_num].Ys &&
	 								 gTpInfo.x[0] <= gSldMenu_Info[sldmenu_num].Xe && gTpInfo.y[0] <= gSldMenu_Info[sldmenu_num].Ye))) // ����
	{
//		SLDMfirsttouch = 0;
		if ((gSldMenu_Info[sldmenu_num].dir & 0x01) == 0) // up and down
			temp = gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L2 - gSldMenu_Info[sldmenu_num].L1;
		else // left and right
			temp = gSldMenu_Info[sldmenu_num].Xe - gSldMenu_Info[sldmenu_num].Xs - gSldMenu_Info[sldmenu_num].L2 - gSldMenu_Info[sldmenu_num].L1;
					V_dev = 0;

		if ((gSldMenu_Info[sldmenu_num].pos % temp) > (temp / 2))
		{
			V = (gSldMenu_Info[sldmenu_num].pos / temp + 1) * gSldMenu_Info[sldmenu_num].step + gSldMenu_Info[sldmenu_num].V_min;
			gSldMenu_Info[sldmenu_num].pos = (V - gSldMenu_Info[sldmenu_num].V_min) / gSldMenu_Info[sldmenu_num].step * temp;
			if (V > gSldMenu_Info[sldmenu_num].V_max - V_dev)
				V = gSldMenu_Info[sldmenu_num].V_min;

			var[gSldMenu_Info[sldmenu_num].p_add * 2] = (V >> 8) & 0xFF;
			var[gSldMenu_Info[sldmenu_num].p_add * 2 + 1] = V & 0xFF;
		}
		else
		{
			V = (gSldMenu_Info[sldmenu_num].pos / temp) * gSldMenu_Info[sldmenu_num].step + gSldMenu_Info[sldmenu_num].V_min;
			gSldMenu_Info[sldmenu_num].pos = (V - gSldMenu_Info[sldmenu_num].V_min) / gSldMenu_Info[sldmenu_num].step * temp;
			if (V > gSldMenu_Info[sldmenu_num].V_max - V_dev)
				V = gSldMenu_Info[sldmenu_num].V_min;

			var[gSldMenu_Info[sldmenu_num].p_add * 2] = (V >> 8) & 0xFF;
			var[gSldMenu_Info[sldmenu_num].p_add * 2 + 1] = V & 0xFF;
		}
		if (gSldMenu_Info[sldmenu_num].Code == 0xC006)
		{
			rebuf[3] = 0x41;
			rebuf[4] = gSldMenu_Info[sldmenu_num].p_add >> 8;
			rebuf[5] = gSldMenu_Info[sldmenu_num].p_add & 0xFF;
			rebuf[6] = var[gSldMenu_Info[sldmenu_num].p_add * 2];
			rebuf[7] = var[gSldMenu_Info[sldmenu_num].p_add * 2 + 1];
			LT_SendData_CRC_Frame(rebuf, 5);
		}
		dp_menu(sldmenu_num);
		if (gSldMenu_Info[sldmenu_num].p_add >= VAR_ADDR_S)
			reg_operation(gSldMenu_Info[sldmenu_num].p_add);

		page_date_update(pic_id);
		sldmenu_flag = 0;
		button_Press_flag = 0;
	}

}

/***********************************************************************************
 * Function Name : dp_menu
 * Description   : Display menu.
 * Input         : - num: which number of sliding menu
 * Output        : None
 * Return        : None
 ************************************************************************************/
void dp_menu(uint8_t num)
{
	uint8_t buff[12] = {0};
	uint16_t box_w, box_h, box_mw, box_mh;

	LT_ReadFlash_UI(buff, addr_index[10] + 12 * gSldMenu_Info[num].frontID + multi_language * 12 * addr_index[11], 12);
	pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
	Sldw = buff[4] + (buff[5] << 8);
	Sldh = buff[6] + (buff[7] << 8);
	pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
	pic_flag = buff[11];

	PICINFO[1].addr = pic_add;
	PICINFO[1].w = Sldw;
	PICINFO[1].h = Sldh;
	PICINFO[1].len = pic_len;
	PICINFO[1].flag = pic_flag;

	LT_ReadFlash_UI(buff, addr_index[10] + 12 * gSldMenu_Info[num].bgID + multi_language * 12 * addr_index[11], 12);
	pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
	Sldw = buff[4] + (buff[5] << 8);
	Sldh = buff[6] + (buff[7] << 8);
	pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
	pic_flag = buff[11];

	PICINFO[0].addr = pic_add;
	PICINFO[0].w = Sldw;
	PICINFO[0].h = Sldh;
	PICINFO[0].len = pic_len;
	PICINFO[0].flag = pic_flag;

	
	if ((gSldMenu_Info[num].dir & 0x01) == 0) // up and down
	{
		if (gSldMenu_Info[num].pos > Sldh)
			gSldMenu_Info[num].pos = Sldh;

		box_h = gSldMenu_Info[num].Ye - gSldMenu_Info[num].Ys;
		box_mh = box_h - gSldMenu_Info[num].L1 - gSldMenu_Info[num].L2;

		if (gSldMenu_Info[num].pos == 0 || gSldMenu_Info[num].pos == Sldh)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{

				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
//					LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
//										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
//										PICINFO[0].w, box_h, FullScreen_flag);
					LT268_BG_to_buffer(0, 0, PICINFO[0].w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, PICINFO[0].w, box_h);
				
				LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
									0, Sldh - gSldMenu_Info[num].L1, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L1, PICINFO[0].flag);

				LT268_pic_to_buffer(0, box_h - gSldMenu_Info[num].L2, PICINFO[0].w, m_PngData,
									0, box_mh, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L2, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(0, gSldMenu_Info[num].L1, PICINFO[1].w, m_PngData,
										0, 0, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, box_mh, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos < gSldMenu_Info[num].L1)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{

				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
//					LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
//										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
//										PICINFO[0].w, box_h, FullScreen_flag);
					LT268_BG_to_buffer(0, 0, PICINFO[0].w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, PICINFO[0].w, box_h);
				
				LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
									0, Sldh - (gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos), PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos, PICINFO[0].flag);
				LT268_pic_to_buffer(0, gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos, PICINFO[0].w, m_PngData,
									0, 0, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].pos, PICINFO[0].flag);

				LT268_pic_to_buffer(0, box_h - gSldMenu_Info[num].L2, PICINFO[0].w, m_PngData,
									0, gSldMenu_Info[num].pos + box_mh, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L2, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(0, gSldMenu_Info[num].L1, PICINFO[1].w, m_PngData,
										0, gSldMenu_Info[num].pos, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, box_mh, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos <= (Sldh - (box_h - gSldMenu_Info[num].L1))) // In the middle
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
//					LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
//										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
//										PICINFO[0].w, box_h, FullScreen_flag);
					LT268_BG_to_buffer(0, 0, PICINFO[0].w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, PICINFO[0].w, box_h);
				
				LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
									0, gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L1, PICINFO[0].flag);

				LT268_pic_to_buffer(0, box_h - gSldMenu_Info[num].L2, PICINFO[0].w, m_PngData,
									0, gSldMenu_Info[num].pos + box_mh, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L2, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(0, gSldMenu_Info[num].L1, PICINFO[1].w, m_PngData,
										0, gSldMenu_Info[num].pos, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, box_mh, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos <= (Sldh - box_mh))
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{

				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
//					LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
//										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
//										PICINFO[0].w, box_h, FullScreen_flag);
					LT268_BG_to_buffer(0, 0, PICINFO[0].w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, PICINFO[0].w, box_h);
				
				LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
									0, gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L1, PICINFO[0].flag);

				LT268_pic_to_buffer(0, box_h - gSldMenu_Info[num].L2, PICINFO[0].w, m_PngData,
									0, gSldMenu_Info[num].pos + box_mh, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, Sldh - (gSldMenu_Info[num].pos + box_mh), PICINFO[0].flag);
				LT268_pic_to_buffer(0, box_h - gSldMenu_Info[num].L2 + Sldh - (gSldMenu_Info[num].pos + box_mh), PICINFO[0].w, m_PngData,
									0, 0, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L2 - (Sldh - (gSldMenu_Info[num].pos + box_mh)), PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(0, gSldMenu_Info[num].L1, PICINFO[1].w, m_PngData,
										0, gSldMenu_Info[num].pos, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, box_mh, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos < Sldh)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{

				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
//					LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
//										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
//										PICINFO[0].w, box_h, FullScreen_flag);
					LT268_BG_to_buffer(0, 0, PICINFO[0].w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, PICINFO[0].w, box_h);
				
				LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
									0, gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L1, PICINFO[0].flag);

				LT268_pic_to_buffer(0, box_h - gSldMenu_Info[num].L2, PICINFO[0].w, m_PngData,
									0, gSldMenu_Info[num].pos + box_mh - Sldh, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L2, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(0, gSldMenu_Info[num].L1, PICINFO[1].w, m_PngData,
										0, gSldMenu_Info[num].pos, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, Sldh - gSldMenu_Info[num].pos, PICINFO[1].flag);
					LT268_pic_to_buffer(0, gSldMenu_Info[num].L1 + Sldh - gSldMenu_Info[num].pos, PICINFO[1].w, m_PngData,
										0, 0, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, box_mh - (Sldh - gSldMenu_Info[num].pos), PICINFO[1].flag);
				}
			}
		}

		// display
		LT268_buffer_to_TFT(0, 0, PICINFO[0].w, m_PngData,
							gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, PICINFO[0].w, box_h);
	}
	else if ((gSldMenu_Info[num].dir & 0x01) == 1) // the left and right sides
	{
		if (gSldMenu_Info[num].pos > Sldw)
			gSldMenu_Info[num].pos = Sldw;

		box_w = gSldMenu_Info[num].Xe - gSldMenu_Info[num].Xs;
		box_h = gSldMenu_Info[num].Ye - gSldMenu_Info[num].Ys;
		box_mw = box_w - gSldMenu_Info[num].L1 - gSldMenu_Info[num].L2;

		if (gSldMenu_Info[num].pos == 0 || gSldMenu_Info[num].pos == Sldw)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
//					LT268_pic_to_buffer(0, 0, box_w, m_PngData,
//										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
//										box_w, box_h, FullScreen_flag);
					LT268_BG_to_buffer(0, 0, box_w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, box_w, box_h);
				
				LT268_pic_to_buffer(0, 0, box_w, m_PngData,
									Sldw - gSldMenu_Info[num].L1, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L1, box_h, PICINFO[0].flag);

				LT268_pic_to_buffer(box_w - gSldMenu_Info[num].L2, 0, box_w, m_PngData,
									box_mw, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L2, box_h, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(gSldMenu_Info[num].L1, 0, box_w, m_PngData,
										0, 0, PICINFO[1].w, PICINFO[1].addr,
										box_mw, box_h, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos < gSldMenu_Info[num].L1)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{

				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
//					LT268_pic_to_buffer(0, 0, box_w, m_PngData,
//										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
//										box_w, box_h, FullScreen_flag);
					LT268_BG_to_buffer(0, 0, box_w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, box_w, box_h);
				
				LT268_pic_to_buffer(0, 0, box_w, m_PngData,
									Sldw - (gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos), 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos, box_h, PICINFO[0].flag);
				LT268_pic_to_buffer(gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos, 0, box_w, m_PngData,
									0, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].pos, box_h, PICINFO[0].flag);

				LT268_pic_to_buffer(box_w - gSldMenu_Info[num].L2, 0, box_w, m_PngData,
									gSldMenu_Info[num].pos + box_mw, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L2, box_h, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(gSldMenu_Info[num].L1, 0, box_w, m_PngData,
										gSldMenu_Info[num].pos, 0, PICINFO[1].w, PICINFO[1].addr,
										box_mw, box_h, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos <= (Sldw - (box_w - gSldMenu_Info[num].L1))) // In the middle
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
//					LT268_pic_to_buffer(0, 0, box_w, m_PngData,
//										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
//										box_w, box_h, FullScreen_flag);
					LT268_BG_to_buffer(0, 0, box_w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, box_w, box_h);
				
				LT268_pic_to_buffer(0, 0, box_w, m_PngData,
									gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L1, box_h, PICINFO[0].flag);

				LT268_pic_to_buffer(box_w - gSldMenu_Info[num].L2, 0, box_w, m_PngData,
									gSldMenu_Info[num].pos + box_mw, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L2, box_h, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(gSldMenu_Info[num].L1, 0, box_w, m_PngData,
										gSldMenu_Info[num].pos, 0, PICINFO[1].w, PICINFO[1].addr,
										box_mw, box_h, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos <= (Sldw - box_mw))
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
//					LT268_pic_to_buffer(0, 0, box_w, m_PngData,
//										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
//										box_w, box_h, FullScreen_flag);
					LT268_BG_to_buffer(0, 0, box_w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, box_w, box_h);
				
				LT268_pic_to_buffer(0, 0, box_w, m_PngData,
									gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L1, box_h, PICINFO[0].flag);

				LT268_pic_to_buffer(box_w - gSldMenu_Info[num].L2, 0, box_w, m_PngData,
									gSldMenu_Info[num].pos + box_mw, 0, PICINFO[0].w, PICINFO[0].addr,
									Sldw - (gSldMenu_Info[num].pos + box_mw), box_h, PICINFO[0].flag);
				LT268_pic_to_buffer(box_w - gSldMenu_Info[num].L2 + Sldw - (gSldMenu_Info[num].pos + box_mw), 0, box_w, m_PngData,
									0, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L2 - (Sldw - (gSldMenu_Info[num].pos + box_mw)), box_h, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(gSldMenu_Info[num].L1, 0, box_w, m_PngData,
										gSldMenu_Info[num].pos, 0, PICINFO[1].w, PICINFO[1].addr,
										box_mw, box_h, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos < Sldw)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
//					LT268_pic_to_buffer(0, 0, box_w, m_PngData,
//										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, LCD_XSIZE_TFT, FullScreen_addr,
//										box_w, box_h, FullScreen_flag);
					LT268_BG_to_buffer(0, 0, box_w, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, box_w, box_h);
				
				LT268_pic_to_buffer(0, 0, box_w, m_PngData,
									gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L1, box_h, PICINFO[0].flag);

				LT268_pic_to_buffer(box_w - gSldMenu_Info[num].L2, 0, box_w, m_PngData,
									gSldMenu_Info[num].pos + box_mw - Sldw, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L2, box_h, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(gSldMenu_Info[num].L1, 0, box_w, m_PngData,
										gSldMenu_Info[num].pos, 0, PICINFO[1].w, PICINFO[1].addr,
										Sldw - gSldMenu_Info[num].pos, box_h, PICINFO[1].flag);
					LT268_pic_to_buffer(gSldMenu_Info[num].L1 + Sldw - gSldMenu_Info[num].pos, 0, box_w, m_PngData,
										0, 0, PICINFO[1].w, PICINFO[1].addr,
										box_mw - (Sldw - gSldMenu_Info[num].pos), box_h, PICINFO[1].flag);
				}
			}
		}
		// display
		LT268_buffer_to_TFT(0, 0, box_w, m_PngData,
							gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, box_w, box_h);
	}
}

/***********************************************************************************
 * Function Name : DL_menu
 * Description   : Get info of sliding menu.
 * Input         : - num: which number of sliding menu
 * Output        : None
 * Return        : None
 ************************************************************************************/
void DL_menu(uint8_t num)
{
	uint8_t buff[12] = {0};

	LT_ReadFlash_UI(buff, addr_index[10] + 12 * gSldMenu_Info[num].frontID + multi_language * 12 * addr_index[11], 12);
	pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
	Sldw = buff[4] + (buff[5] << 8);
	Sldh = buff[6] + (buff[7] << 8);
	pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
	pic_flag = buff[11];

	gSldMenu_Info[num].flag = pic_flag;

	// LT_ReadFlash_UI(buff, addr_index[10] + 12 * gSldMenu_Info[num].bgID + multi_language * 12 * addr_index[11], 12);
	// pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
	// Sldw = buff[4] + (buff[5] << 8);
	// Sldh = buff[6] + (buff[7] << 8);
	// pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
	// pic_flag = buff[11];
}



/***********************************************************************************
 * Function Name : input_display
 * Description   : Display ASCII data on screen.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void input_display(void)
{
	uint16_t x, y;
	uint32_t zk_addr, fcolor;
	uint8_t font_w, font_h, Alignment;
	uint8_t buff1[4];
	uint16_t box_x, box_y, box_w, box_h;

	LT_ReadFlash_UI(buff1, addr_index[2] + gDio_Info[Dio_num].zk_id * 8, 4);
	zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
	font_w = gDio_Info[Dio_num].zk_w;
	font_h = gDio_Info[Dio_num].zk_h; 

	fcolor = gDio_Info[Dio_num].fcolor;
	Alignment = gDio_Info[Dio_num].Alig;

//    box_x = gDio_Info[Dio_num].dp_x + gDio_Info[Dio_num].kb_x;
    box_y = gDio_Info[Dio_num].dp_y + gDio_Info[Dio_num].kb_y;

    if (Alignment == 0)
    {
        box_x = gDio_Info[Dio_num].dp_x + gDio_Info[Dio_num].kb_x;
        box_w = PICINFO[0].w - gDio_Info[Dio_num].dp_x - 1;
    }
    else if (Alignment == 2)
    {
        box_x = gDio_Info[Dio_num].kb_x;
        box_w = gDio_Info[Dio_num].dp_x + 1 - cur_w;
    }
    box_h = font_h;

	// debug
//		printf(" Alignment  %d , font_w font_h  %d  %d  \r\n",Alignment,font_w,font_h);
//		printf(" PICINFO   %d  %d  %d\r\n",PICINFO[0].x,gDio_Info[Dio_num].dp_x,PICINFO[0].w);
//		printf(" xy  %d %d   box_w,box_h %d %d  \r\n",x,y,box_w,box_h);

	LT_Print_zk_Font(4, zk_addr,
					 LAY_BUFF1, LCD_XSIZE_TFT, font_w, font_h, Alignment, fcolor, Black, 0, 1, PICINFO[0], 0,
					 box_x, box_y, box_x + box_w - 1, box_y + box_h - 1,
					 0, 0, Display_buff, sizeof(Display_buff));
	input_w = data_w;
	Cusor_time = 60;

}

uint8_t buff_to_var(uint8_t *buff)
{
	uint8_t i = 0;
	int64_t sum = 0;

	if (neg_flag == 0) // positive number
	{
		for (i = 0; i < i_len; i++)
		{
			sum += pow(10, i_len - 1 - i + gDio_Info[Dio_num].D_num) * (buff[i] - '0');
		}
		for (i = 0; i < d_len; i++)
		{
			sum += pow(10, gDio_Info[Dio_num].D_num - 1 - i) * (buff[i_len + 1 + i] - '0');
		}
	}
	else // negative number
	{
		for (i = 0; i < i_len; i++)
		{
			sum += pow(10, i_len - 1 - i + gDio_Info[Dio_num].D_num) * (buff[i + 1] - '0');
		}
		for (i = 0; i < d_len; i++)
		{
			sum += pow(10, gDio_Info[Dio_num].D_num - 1 - i) * (buff[i_len + 2 + i] - '0');
		}
		sum = sum * (-1);
	}

	if (gDio_Info[Dio_num].Limite_EN == 1)
	{
		if (sum >= gDio_Info[Dio_num].V_min && sum <= gDio_Info[Dio_num].V_max) // The value is within the range limit
		{
			if (gDio_Info[Dio_num].p_tpye == 0x00 || gDio_Info[Dio_num].p_tpye == 0x80)
			{
				var[gDio_Info[Dio_num].p_add * 2 + 1] = sum;
			}
			else if (gDio_Info[Dio_num].p_tpye == 0x01 || gDio_Info[Dio_num].p_tpye == 0x81)
			{
				var[gDio_Info[Dio_num].p_add * 2] = sum >> 8 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 1] = sum & 0xFF;
			}
			else if (gDio_Info[Dio_num].p_tpye == 0x02 || gDio_Info[Dio_num].p_tpye == 0x82)
			{

				var[gDio_Info[Dio_num].p_add * 2] = sum >> 24 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 1] = sum >> 16 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 2] = sum >> 8 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 3] = sum & 0xFF;
			}
			else if (gDio_Info[Dio_num].p_tpye == 0x83)
			{
				if (sum < 0)
				{
					var[gDio_Info[Dio_num].p_add * 2] = sum >> 56 & 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 1] = sum >> 48 & 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 2] = sum >> 40 & 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 3] = sum >> 32 & 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 4] = sum >> 24 & 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 5] = sum >> 16 & 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 6] = sum >> 8 & 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 7] = sum & 0xFF;
				}
				else
				{
					var[gDio_Info[Dio_num].p_add * 2] = sum >> 56 & 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 1] = sum >> 48 & 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 2] = sum >> 40 & 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 3] = sum >> 32 & 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 4] = sum >> 24 & 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 5] = sum >> 16 & 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 6] = sum >> 8 & 0xFF;
					var[gDio_Info[Dio_num].p_add * 2 + 7] = sum & 0xFF;
				}
			}
			return 0;
		}
		else
			return 1; // Not within the range of values
	}
	else
	{
		if (gDio_Info[Dio_num].p_tpye == 0x00 || gDio_Info[Dio_num].p_tpye == 0x80)
		{
			var[gDio_Info[Dio_num].p_add * 2 + 1] = sum;
		}
		else if (gDio_Info[Dio_num].p_tpye == 0x01 || gDio_Info[Dio_num].p_tpye == 0x81)
		{
			var[gDio_Info[Dio_num].p_add * 2] = sum >> 8 & 0xFF;
			var[gDio_Info[Dio_num].p_add * 2 + 1] = sum & 0xFF;
		}
		else if (gDio_Info[Dio_num].p_tpye == 0x02 || gDio_Info[Dio_num].p_tpye == 0x82)
		{
			var[gDio_Info[Dio_num].p_add * 2] = sum >> 24 & 0xFF;
			var[gDio_Info[Dio_num].p_add * 2 + 1] = sum >> 16 & 0xFF;
			var[gDio_Info[Dio_num].p_add * 2 + 2] = sum >> 8 & 0xFF;
			var[gDio_Info[Dio_num].p_add * 2 + 3] = sum & 0xFF;
		}
		else if (gDio_Info[Dio_num].p_tpye == 0x83)
		{
			if (sum < 0)
			{
				var[gDio_Info[Dio_num].p_add * 2] = sum >> 56 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 1] = sum >> 48 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 2] = sum >> 40 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 3] = sum >> 32 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 4] = sum >> 24 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 5] = sum >> 16 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 6] = sum >> 8 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 7] = sum & 0xFF;
			}
			else
			{
				var[gDio_Info[Dio_num].p_add * 2] = sum >> 56 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 1] = sum >> 48 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 2] = sum >> 40 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 3] = sum >> 32 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 4] = sum >> 24 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 5] = sum >> 16 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 6] = sum >> 8 & 0xFF;
				var[gDio_Info[Dio_num].p_add * 2 + 7] = sum & 0xFF;
			}
		}
		return 0;
	}
}

/***********************************************************************************
 * Function Name : data_input
 * Description   : Touch detection of ASCII keyboard.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void data_input(void)
{
	uint8_t res = 0;
	uint16_t i = 0;
	uint8_t buff[12] = {0};
	uint8_t rebuf[20];
	uint32_t zk_addr = 0;
	uint8_t width_Hor = 0;
	uint32_t color;

	// press down
	if (gTpInfo.sta && DioKb_flag == 0)
	{
		for (i = 0; i < Dio_count; i++)
		{
			if (gTpInfo.x[0] >= gDio_Info[i].Xs && gTpInfo.y[0] >= gDio_Info[i].Ys &&
				gTpInfo.x[0] <= gDio_Info[i].Xe && gTpInfo.y[0] <= gDio_Info[i].Ye &&
				Dio_flag == 0 && button_Press_flag == 0)
			{
				Dio_num = i;
				Dio_flag = 1;
				button_Press_flag = 1;
				if (buzzer)
					touch_buzzer();
			}
		}
	}
	
	if (Button_Key_Code_Flag == 1)
	{
		for (i = 0; i < Dio_count; i++)
		{
			if (gDio_Info[i].Xs == 0xFFFF && gDio_Info[i].Ys ==  Button_Key_Code)
			{
				Button_Key_Code_Flag = 0;
				Button_Key_Code = 0;
				Dio_num = i;
				Dio_flag = 1;
				if (Pop_up_flag == 1) // pop-up window
				{
				}
				
				LT_ReadFlash_UI(buff, addr_index[6] + 12 * gDio_Info[Dio_num].kb_id, 12);
				PICINFO[0].addr = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
				PICINFO[0].w = buff[4] + (buff[5] << 8);
				PICINFO[0].h = buff[6] + (buff[7] << 8);
				PICINFO[0].len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
				PICINFO[0].flag = buff[11];
				PICINFO[0].x = gDio_Info[Dio_num].kb_x;
				PICINFO[0].y = gDio_Info[Dio_num].kb_y;
				
				pic_id_temp = pic_id;
				pic_id = gDio_Info[i].kb_id;
				
				if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
				{
					if (PICINFO[0].flag == 0 || PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
						LT_ShowPicture(gDio_Info[Dio_num].kb_x, gDio_Info[Dio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr, pic_len, PICINFO[0].flag); 
				}
				
				/*Dynamic picture coverage judgment*/
				DioKb_flag = 1;
				gDio_Info[Dio_num].Xs = gDio_Info[Dio_num].kb_x;
				gDio_Info[Dio_num].Ys = gDio_Info[Dio_num].kb_y;
				gDio_Info[Dio_num].Xe = gDio_Info[Dio_num].kb_x + PICINFO[0].w;
				gDio_Info[Dio_num].Ye = gDio_Info[Dio_num].kb_y + PICINFO[0].h;

				/************/
				LT_ReadFlash_UI(buff, addr_index[2] + gDio_Info[Dio_num].zk_id * 8, 4);
				zk_addr = buff[0] + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);

				LT_ReadFlash_UI(&gDio_Info[Dio_num].zk_h, zk_addr + 3, 1); 

				if (gDio_Info[i].cursor_color == 0)
					color = Black;
				else
					color = White;

				LT_ReadFlash_UI(&cur_w, zk_addr + 9 + 92, 1);
//				cur_w = gDio_Info[Dio_num].zk_w;
				
				if (gDio_Info[Dio_num].Alig == 0)
					cur_x = gDio_Info[Dio_num].dp_x + gDio_Info[Dio_num].kb_x;
				else
					cur_x = gDio_Info[Dio_num].dp_x + gDio_Info[Dio_num].kb_x - cur_w;
				cur_y = gDio_Info[Dio_num].dp_y + gDio_Info[Dio_num].kb_y;
				
				buff[0] = '|';
				buff[1] = 0;
				
				LT_Print_zk_Font(4, zk_addr,
								 LAY_BUFF1, LCD_XSIZE_TFT, gDio_Info[Dio_num].zk_w, gDio_Info[Dio_num].zk_h, gDio_Info[Dio_num].Alig, color, Black, 0, 1, PICINFO[0], 0,
								 cur_x, cur_y, cur_x + cur_w + 1, cur_y + gDio_Info[Dio_num].zk_h -1,
								 0, 0, buff, 1);  


				Get_Touch_info(gDio_Info[i].kb_id);
				button_Press_flag = 0;
				Cusor_time = 0;
				Dio_flag = 0;
				i_len = 0;
				d_len = 0;
				input_len = 0;
				neg_flag = 0;
				dot_flag = 0;
				input_w = 0;
				memset(Display_buff, 0, sizeof(Display_buff));
				break;
			}
		}
	}

	// raise
	if (gTpInfo.sta == 0 && Dio_flag == 1 && DioKb_flag == 0)
	{
		if (Pop_up_flag == 1) // pop-up window
		{
		}

		LT_ReadFlash_UI(buff, addr_index[6] + 12 * gDio_Info[Dio_num].kb_id, 12);
		PICINFO[0].addr = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
		PICINFO[0].w = buff[4] + (buff[5] << 8);
		PICINFO[0].h = buff[6] + (buff[7] << 8);
		PICINFO[0].len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
		PICINFO[0].flag = buff[11];
		PICINFO[0].x = gDio_Info[Dio_num].kb_x;
		PICINFO[0].y = gDio_Info[Dio_num].kb_y;
		
		pic_id_temp = pic_id;
		pic_id = gDio_Info[Dio_num].kb_id;

		if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
		{
			if (PICINFO[0].flag == 0 || PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
				LT_ShowPicture(gDio_Info[Dio_num].kb_x, gDio_Info[Dio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr, pic_len, PICINFO[0].flag); 
		}

		/*Dynamic picture coverage judgment*/
		DioKb_flag = 1;
		gDio_Info[Dio_num].Xs = gDio_Info[Dio_num].kb_x;
		gDio_Info[Dio_num].Ys = gDio_Info[Dio_num].kb_y;
		gDio_Info[Dio_num].Xe = gDio_Info[Dio_num].kb_x + PICINFO[0].w;
		gDio_Info[Dio_num].Ye = gDio_Info[Dio_num].kb_y + PICINFO[0].h;

		LT_ReadFlash_UI(buff, addr_index[2] + gDio_Info[Dio_num].zk_id * 8, 4);
		zk_addr = buff[0] + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);

		LT_ReadFlash_UI(&gDio_Info[Dio_num].zk_h, zk_addr + 3, 1); 


		if (gDio_Info[Dio_num].cursor_color == 0)
			color = Black;
		else
			color = White;
		
		LT_ReadFlash_UI(&cur_w, zk_addr + 9 + 92, 1);
//		cur_w = gDio_Info[Dio_num].zk_w;

		if (gDio_Info[Dio_num].Alig == 0)
			cur_x = gDio_Info[Dio_num].dp_x + gDio_Info[Dio_num].kb_x;
		else
			cur_x = gDio_Info[Dio_num].dp_x + gDio_Info[Dio_num].kb_x - cur_w;
		cur_y = gDio_Info[Dio_num].dp_y + gDio_Info[Dio_num].kb_y;
	
		
		buff[0] = '|';
		buff[1] = 0;
		
		LT_Print_zk_Font(4, zk_addr,
						 LAY_BUFF1, LCD_XSIZE_TFT, gDio_Info[Dio_num].zk_w, gDio_Info[Dio_num].zk_h, gDio_Info[Dio_num].Alig, color, Black, 0, 1, PICINFO[0], 0,
						 cur_x, cur_y, cur_x + cur_w + 1, cur_y + gDio_Info[Dio_num].zk_h -1,
						 0, 0, buff, 1);  
		
		Get_Touch_info(gDio_Info[Dio_num].kb_id);  //get info
		button_Press_flag = 0;
		Cusor_time = 0;
		Dio_flag = 0;
		i_len = 0;
		d_len = 0;
		input_len = 0;
		neg_flag = 0;
		dot_flag = 0;
		input_w = 0;
		memset(Display_buff, 0, sizeof(Display_buff));
	}

	// Press down within the range of keyboard
	if (gTpInfo.sta && DioKb_flag == 1 && Dio_flag == 0)
	{
		for (i = 0; i < Kb_count; i++)
		{
			if (gTpInfo.x[0] >= gKb_Info[i].Xs + gDio_Info[Dio_num].kb_x && gTpInfo.y[0] >= gKb_Info[i].Ys + gDio_Info[Dio_num].kb_y &&
				gTpInfo.x[0] <= gKb_Info[i].Xe + gDio_Info[Dio_num].kb_x && gTpInfo.y[0] <= gKb_Info[i].Ye + gDio_Info[Dio_num].kb_y &&
				Kb_flag == 0)
			{
				if (gKb_Info[i].press_id != 0xFFFF)
				{
					LT_ReadFlash_UI(buff, addr_index[6] + 12 * gKb_Info[i].press_id, 12);
					pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
					pic_w = buff[4] + (buff[5] << 8);
					pic_h = buff[6] + (buff[7] << 8);
					pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
					pic_flag = buff[11];

					LT268_dispaly_CutPicture(gDio_Info[Dio_num].kb_x + gKb_Info[i].Xs, gDio_Info[Dio_num].kb_y + gKb_Info[i].Ys,
											 gKb_Info[i].Xs, gKb_Info[i].Ys, gKb_Info[i].Xe - gKb_Info[i].Xs + 1, gKb_Info[i].Ye - gKb_Info[i].Ys + 1,
											 pic_w, pic_add, pic_len, pic_flag);
				}
				Kb_num = i;
				Kb_flag = 1;
				if (buzzer)
					touch_buzzer();
			}
		}
	}

	// raise
	if (gTpInfo.sta == 0 && DioKb_flag == 1 && Kb_flag == 1)
	{
		LT_ReadFlash_UI(buff, addr_index[6] + 12 * gDio_Info[Dio_num].kb_id, 12);
		PICINFO[0].addr = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
		PICINFO[0].w = buff[4] + (buff[5] << 8);
		PICINFO[0].h = buff[6] + (buff[7] << 8);
		PICINFO[0].len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
		PICINFO[0].flag = buff[11];
		PICINFO[0].x = gDio_Info[Dio_num].kb_x;
		PICINFO[0].y = gDio_Info[Dio_num].kb_y;

		if (gKb_Info[Kb_num].press_id != 0xFFFF)
		{

			LT268_dispaly_CutPicture(gDio_Info[Dio_num].kb_x + gKb_Info[Kb_num].Xs, gDio_Info[Dio_num].kb_y + gKb_Info[Kb_num].Ys,
									 gKb_Info[Kb_num].Xs, gKb_Info[Kb_num].Ys, gKb_Info[Kb_num].Xe - gKb_Info[Kb_num].Xs + 1, gKb_Info[Kb_num].Ye - gKb_Info[Kb_num].Ys + 1,
									 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);
		}

		if (gKb_Info[Kb_num].Keyvalue == 0x2E && gDio_Info[Dio_num].D_num > 0 && dot_flag == 0) // '.'
		{
			if ((input_len > 0 && neg_flag == 0) || (input_len > 1 && neg_flag == 1))
			{
				Display_buff[input_len] = gKb_Info[Kb_num].Keyvalue & 0xff;
				input_len++;
				dot_flag = 1;
				input_display();
			}
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0x2D && neg_flag == 0 && i_len == 0 && d_len == 0) // '-'
		{
			if (gDio_Info[Dio_num].p_tpye == 0x80 || gDio_Info[Dio_num].p_tpye == 0x81 || gDio_Info[Dio_num].p_tpye == 0x82 || gDio_Info[Dio_num].p_tpye == 0x83)
			{
				neg_flag = 1;
				Display_buff[input_len] = gKb_Info[Kb_num].Keyvalue & 0xff;
				input_len++;
				input_display();
			}
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0xF0) // cancel
		{
			DioKb_flag = 0;
			if (Pop_up_flag == 0)
				Display_page(pic_id_temp);
			else if (Pop_up_flag == 1)
			{
				Display_pop_up(Pop_up_id, Pop_up_x, Pop_up_y);
			}
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0xF2) // backspace
		{
			if (dot_flag == 1) // with decimal point
			{
				if (d_len > 0)
				{
					d_len--;
				}
				else
					dot_flag = 0;
			}
			else if (i_len > 0)
				i_len--;

			if (input_len > 0)
			{
				input_len--;
				if (input_len == 0 && neg_flag == 1)
					neg_flag = 0;
				Display_buff[input_len] = 0x00;
				input_display();
			}
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0xF1) // confirm
		{
			res = buff_to_var(Display_buff);
			if (res == 0)
			{
				if (gDio_Info[Dio_num].Code == 0xC002)
				{
					rebuf[3] = 0x41;
					rebuf[4] = gDio_Info[Dio_num].p_add >> 8;
					rebuf[5] = gDio_Info[Dio_num].p_add & 0xFF;
					if (gDio_Info[Dio_num].p_tpye == 0x00 || gDio_Info[Dio_num].p_tpye == 0x80)
					{
						rebuf[6] = var[gDio_Info[Dio_num].p_add * 2];
						rebuf[7] = var[gDio_Info[Dio_num].p_add * 2 + 1];
						LT_InfoFeedback_with_addr(rebuf, 5);
					}
					else if (gDio_Info[Dio_num].p_tpye == 0x01 || gDio_Info[Dio_num].p_tpye == 0x81)
					{
						rebuf[6] = var[gDio_Info[Dio_num].p_add * 2];
						rebuf[7] = var[gDio_Info[Dio_num].p_add * 2 + 1];
						LT_InfoFeedback_with_addr(rebuf, 5);
					}
					else if (gDio_Info[Dio_num].p_tpye == 0x02 || gDio_Info[Dio_num].p_tpye == 0x82)
					{
						rebuf[6] = var[gDio_Info[Dio_num].p_add * 2];
						rebuf[7] = var[gDio_Info[Dio_num].p_add * 2 + 1];
						rebuf[8] = var[gDio_Info[Dio_num].p_add * 2 + 2];
						rebuf[9] = var[gDio_Info[Dio_num].p_add * 2 + 3];
						LT_InfoFeedback_with_addr(rebuf, 7);
					}
					else if (gDio_Info[Dio_num].p_tpye == 0x03 || gDio_Info[Dio_num].p_tpye == 0x83)
					{
						rebuf[6] = var[gDio_Info[Dio_num].p_add * 2];
						rebuf[7] = var[gDio_Info[Dio_num].p_add * 2 + 1];
						rebuf[8] = var[gDio_Info[Dio_num].p_add * 2 + 2];
						rebuf[9] = var[gDio_Info[Dio_num].p_add * 2 + 3];
						rebuf[10] = var[gDio_Info[Dio_num].p_add * 2 + 4];
						rebuf[11] = var[gDio_Info[Dio_num].p_add * 2 + 5];
						rebuf[12] = var[gDio_Info[Dio_num].p_add * 2 + 6];
						rebuf[13] = var[gDio_Info[Dio_num].p_add * 2 + 7];
						LT_InfoFeedback_with_addr(rebuf, 11);
					}
				}
				DioKb_flag = 0;
				reg_operation(gDio_Info[Dio_num].p_add);
				if (Pop_up_flag == 0)
					Display_page(pic_id_temp);
				else if (Pop_up_flag == 1)
				{
					Display_pop_up(Pop_up_id, Pop_up_x, Pop_up_y);
				}
			}
		}
		else if (gKb_Info[Kb_num].Keyvalue >= '0' && gKb_Info[Kb_num].Keyvalue <= '9') // Digital input
		{
			if ((i_len < gDio_Info[Dio_num].I_num && dot_flag == 0) || (d_len < gDio_Info[Dio_num].D_num && dot_flag == 1))
			{
				Display_buff[input_len] = gKb_Info[Kb_num].Keyvalue & 0xff;
				if (dot_flag == 0)
					i_len++; // Integer length plus
				else
					d_len++; // Decimal length plus
				input_len++; // Display buff length plus

				input_display();
			}
		}
		Kb_flag = 0;
	}
}

/***********************************************************************************
 * Function Name : Ascii_input
 * Description   : Touch detection of ASCII keyboard.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Ascii_input(void)
{
	uint8_t res = 0;
	uint16_t i = 0;
	uint8_t rebuf[50];
	uint8_t buff1[12] = {0};
	uint16_t k = 0;
	uint32_t zk_addr = 0;
	uint8_t width_Hor = 0;
	uint32_t color;

	// press down
	if (gTpInfo.sta && AioKb_flag == 0)
	{
		for (i = 0; i < Aio_count; i++)
		{
			if (gTpInfo.x[0] >= gAio_Info[i].Xs && gTpInfo.y[0] >= gAio_Info[i].Ys &&
				gTpInfo.x[0] <= gAio_Info[i].Xe && gTpInfo.y[0] <= gAio_Info[i].Ye &&
				Aio_flag == 0 && button_Press_flag == 0)
			{
				button_Press_flag = 1;
				Aio_num = i;
				Aio_flag = 1;
				if (buzzer)
					touch_buzzer();
			}
		}
	}
	if (Button_Key_Code_Flag == 1)
	{
		for (i = 0; i < Aio_count; i++)
		{
			if (gAio_Info[i].Xs == 0xFFFF && gAio_Info[i].Ys ==  Button_Key_Code)
			{
				Button_Key_Code_Flag = 0;
				Button_Key_Code = 0;
				Aio_num = i;
				Aio_flag = 1;
				if (Pop_up_flag == 1) // pop-up window
				{
				}
				LT_ReadFlash_UI(buff1, addr_index[6] + 12 * gAio_Info[Aio_num].kb_id, 12);
				pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
				pic_w = buff1[4] + (buff1[5] << 8);
				pic_h = buff1[6] + (buff1[7] << 8);
				pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
				pic_flag = buff1[11];

				// Record picture information of keyboard
				PICINFO[0].addr = pic_add;
				PICINFO[0].w = pic_w;
				PICINFO[0].h = pic_h;
				PICINFO[0].len = pic_len;
				PICINFO[0].flag = pic_flag;
				PICINFO[0].x = gAio_Info[Aio_num].kb_x;
				PICINFO[0].y = gAio_Info[Aio_num].kb_y;

				/*Dynamic picture coverage judgment*/
				AioKb_flag = 1;
				gAio_Info[Aio_num].Xs = gAio_Info[Aio_num].kb_x;
				gAio_Info[Aio_num].Ys = gAio_Info[Aio_num].kb_y;
				gAio_Info[Aio_num].Xe = gAio_Info[Aio_num].kb_x + pic_w;
				gAio_Info[Aio_num].Ye = gAio_Info[Aio_num].kb_y + pic_h;

				LT_ReadFlash_UI(buff1, addr_index[2] + gAio_Info[Aio_num].zk_id * 8, 4);
				gAio_Info[Aio_num].zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
				
				cur_x = gAio_Info[Aio_num].dp_x + gAio_Info[Aio_num].kb_x;
				cur_y = gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y;
				buff1[0] = '|';
				buff1[1] = 0;

				if (gAio_Info[Aio_num].cursor_color == 0)
					color = Black;
				else
					color = White;

		//		cur_w = gAio_Info[Aio_num].zk_w / 2;
				cur_w = gAio_Info[Aio_num].zk_w;

				Get_Touch_info(gAio_Info[Aio_num].kb_id);
				Aio_flag = 0;
				button_Press_flag = 0;
				input_len = 0;
				CapsLock = 0;
				input_w = 0;
				memset(Display_buff, 0, sizeof(Display_buff));
				
				pic_id_temp = pic_id;
				pic_id = gAio_Info[Aio_num].kb_id;

				if (gAio_Info[Aio_num].scan_mode == 1)
				{
					for (k = 0; k < gAio_Info[Aio_num].p_len * 2; k++)
					{
						if (var[gAio_Info[Aio_num].p_add * 2 + k] > 0x7F)
							break;
						Display_buff[k] = var[gAio_Info[Aio_num].p_add * 2 + k];
						if (var[gAio_Info[Aio_num].p_add * 2 + k] == 0x00 && var[gAio_Info[Aio_num].p_add * 2 + k + 1] == 0x00)
							break;
					}

					input_len = k;

					// display keyboard
					if (PICINFO[0].flag == 0 || PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
						LT_ShowPicture(gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr, pic_len, PICINFO[0].flag); 

					// display ASCII data on keyboard
					LT_Print_zk_Font(4, gAio_Info[Aio_num].zk_addr,
									 LAY_BUFF2, LCD_XSIZE_TFT, gAio_Info[Aio_num].zk_w, gAio_Info[Aio_num].zk_h, 3, gAio_Info[Aio_num].fcolor, White, 0, 1, PICINFO[0], gAio_Info[Aio_num].input_mode,
									 gAio_Info[Aio_num].dp_x + gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y,
									 PICINFO[0].x + PICINFO[0].w - 1, gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y + gAio_Info[Aio_num].zk_h - 1,
									 0, 0, Display_buff, input_len);
					
					input_w = data_w;
					
					LT_Print_zk_Font(4, gAio_Info[Aio_num].zk_addr,
									 LAY_BUFF2, LCD_XSIZE_TFT, gAio_Info[Aio_num].zk_w, gAio_Info[Aio_num].zk_h, 3, color, White, 0, 1, PICINFO[0], 0,
									 cur_x + input_w, cur_y,  cur_x + input_w + cur_w + 1, cur_y + gAio_Info[Aio_num].zk_h - 1,
									  0, 0, buff1, 1);
				}
				else
				{
					if (PICINFO[0].flag == 0 || PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
						LT_ShowPicture(gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr, pic_len, PICINFO[0].flag); 

					LT_Print_zk_Font(4, gAio_Info[Aio_num].zk_addr,
									 LAY_BUFF2, LCD_XSIZE_TFT, gAio_Info[Aio_num].zk_w, gAio_Info[Aio_num].zk_h, 3, color, White, 0, 1, PICINFO[0], 0,
									 cur_x, cur_y,  cur_x + cur_w + 1, cur_y + gAio_Info[Aio_num].zk_h - 1,
									  0, 0, buff1, 1);
				}

				// AioKb_flag = 1;
				Cusor_time = 0;
				break;
			}
		}
		
	}
	// keep pressing
	if (gTpInfo.sta == 0 && AioKb_flag == 0 && Aio_flag == 1)
	{
		if (Pop_up_flag == 1) // pop-up window
		{
		}

		LT_ReadFlash_UI(buff1, addr_index[6] + 12 * gAio_Info[Aio_num].kb_id, 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		// Record picture information of keyboard
		PICINFO[0].addr = pic_add;
		PICINFO[0].w = pic_w;
		PICINFO[0].h = pic_h;
		PICINFO[0].len = pic_len;
		PICINFO[0].flag = pic_flag;
		PICINFO[0].x = gAio_Info[Aio_num].kb_x;
		PICINFO[0].y = gAio_Info[Aio_num].kb_y;

		/*Dynamic picture coverage judgment*/
		AioKb_flag = 1;
		gAio_Info[Aio_num].Xs = gAio_Info[Aio_num].kb_x;
		gAio_Info[Aio_num].Ys = gAio_Info[Aio_num].kb_y;
		gAio_Info[Aio_num].Xe = gAio_Info[Aio_num].kb_x + pic_w;
		gAio_Info[Aio_num].Ye = gAio_Info[Aio_num].kb_y + pic_h;

		LT_ReadFlash_UI(buff1, addr_index[2] + gAio_Info[Aio_num].zk_id * 8, 4);
		gAio_Info[Aio_num].zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		
		cur_x = gAio_Info[Aio_num].dp_x + gAio_Info[Aio_num].kb_x;
		cur_y = gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y;
		buff1[0] = '|';
		buff1[1] = 0;

		if (gAio_Info[Aio_num].cursor_color == 0)
			color = Black;
		else
			color = White;

//		cur_w = gAio_Info[Aio_num].zk_w / 2;
		cur_w = gAio_Info[Aio_num].zk_w;

		Get_Touch_info(gAio_Info[Aio_num].kb_id);
		Aio_flag = 0;
		button_Press_flag = 0;
		input_len = 0;
		CapsLock = 0;
		input_w = 0;
		memset(Display_buff, 0, sizeof(Display_buff));
		
		pic_id_temp = pic_id;
		pic_id = gAio_Info[Aio_num].kb_id;

		if (gAio_Info[Aio_num].scan_mode == 1)
		{
			for (k = 0; k < gAio_Info[Aio_num].p_len * 2; k++)
			{
				if (var[gAio_Info[Aio_num].p_add * 2 + k] > 0x7F)
					break;
				Display_buff[k] = var[gAio_Info[Aio_num].p_add * 2 + k];
				if (var[gAio_Info[Aio_num].p_add * 2 + k] == 0x00 && var[gAio_Info[Aio_num].p_add * 2 + k + 1] == 0x00)
					break;
			}

			input_len = k;

			// display keyboard
			if (PICINFO[0].flag == 0 || PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
				LT_ShowPicture(gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr, pic_len, PICINFO[0].flag); 

			// display ASCII data on keyboard
			LT_Print_zk_Font(4, gAio_Info[Aio_num].zk_addr,
							 LAY_BUFF2, LCD_XSIZE_TFT, gAio_Info[Aio_num].zk_w, gAio_Info[Aio_num].zk_h, 3, gAio_Info[Aio_num].fcolor, White, 0, 1, PICINFO[0], gAio_Info[Aio_num].input_mode,
							 gAio_Info[Aio_num].dp_x + gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y,
							 PICINFO[0].x + PICINFO[0].w - 1, gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y + gAio_Info[Aio_num].zk_h - 1,
							 0, 0, Display_buff, input_len);
			
			input_w = data_w;
			
			LT_Print_zk_Font(4, gAio_Info[Aio_num].zk_addr,
							 LAY_BUFF2, LCD_XSIZE_TFT, gAio_Info[Aio_num].zk_w, gAio_Info[Aio_num].zk_h, 3, color, White, 0, 1, PICINFO[0], 0,
							 cur_x + input_w, cur_y,  cur_x + input_w + cur_w + 1, cur_y + gAio_Info[Aio_num].zk_h - 1,
							  0, 0, buff1, 1);
		}
		else
		{
			if (PICINFO[0].flag == 0 || PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
				LT_ShowPicture(gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].kb_y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr, pic_len, PICINFO[0].flag); 

			LT_Print_zk_Font(4, gAio_Info[Aio_num].zk_addr,
							 LAY_BUFF2, LCD_XSIZE_TFT, gAio_Info[Aio_num].zk_w, gAio_Info[Aio_num].zk_h, 3, color, White, 0, 1, PICINFO[0], 0,
							 cur_x, cur_y,  cur_x + cur_w + 1, cur_y + gAio_Info[Aio_num].zk_h - 1,
							  0, 0, buff1, 1);
		}

		// AioKb_flag = 1;
		Cusor_time = 0;
	}

	// press down within the range of keyboard
	if (gTpInfo.sta && AioKb_flag == 1 && Aio_flag == 0)
	{
		for (i = 0; i < Kb_count; i++)
		{
			if (gTpInfo.x[0] >= gKb_Info[i].Xs + gAio_Info[Aio_num].kb_x && gTpInfo.y[0] >= gKb_Info[i].Ys + gAio_Info[Aio_num].kb_y && gTpInfo.x[0] <= gKb_Info[i].Xe + gAio_Info[Aio_num].kb_x && gTpInfo.y[0] <= gKb_Info[i].Ye + gAio_Info[Aio_num].kb_y && Kb_flag == 0)
			{
				if (gKb_Info[i].press_id != 0xFFFF)
				{

					LT_ReadFlash_UI(buff1, addr_index[6] + 12 * gKb_Info[i].press_id, 12);
					pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
					pic_w = buff1[4] + (buff1[5] << 8);
					pic_h = buff1[6] + (buff1[7] << 8);
					pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
					pic_flag = buff1[11];

					LT268_dispaly_CutPicture(gAio_Info[Aio_num].kb_x + gKb_Info[i].Xs, gAio_Info[Aio_num].kb_y + gKb_Info[i].Ys,
											 gKb_Info[i].Xs, gKb_Info[i].Ys, gKb_Info[i].Xe - gKb_Info[i].Xs + 1, gKb_Info[i].Ye - gKb_Info[i].Ys + 1,
											 pic_w, pic_add, pic_len, pic_flag);
				}
				Kb_num = i;
				Kb_flag = 1;
				if (buzzer)
					touch_buzzer();
			}
		}
	}

	// raise
	if (gTpInfo.sta == 0 && AioKb_flag == 1 && Kb_flag == 1)
	{

		LT_ReadFlash_UI(buff1, addr_index[6] + 12 * gAio_Info[Aio_num].kb_id, 12);
		PICINFO[0].addr = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		PICINFO[0].w = buff1[4] + (buff1[5] << 8);
		PICINFO[0].h = buff1[6] + (buff1[7] << 8);
		PICINFO[0].len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		PICINFO[0].flag = buff1[11];
		PICINFO[0].x = gAio_Info[Aio_num].kb_x;
		PICINFO[0].y = gAio_Info[Aio_num].kb_y;

		if ((gKb_Info[Kb_num].press_id != 0xFFFF && gKb_Info[Kb_num].Keyvalue != 0xF3) || CapsLock == 1)
		{
			LT268_dispaly_CutPicture(gAio_Info[Aio_num].kb_x + gKb_Info[Kb_num].Xs, gAio_Info[Aio_num].kb_y + gKb_Info[Kb_num].Ys,
									 gKb_Info[Kb_num].Xs, gKb_Info[Kb_num].Ys, gKb_Info[Kb_num].Xe - gKb_Info[Kb_num].Xs + 1, gKb_Info[Kb_num].Ye - gKb_Info[Kb_num].Ys + 1,
									 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);
		}

		if (gKb_Info[Kb_num].Keyvalue == 0xF0) // cancel
		{
			AioKb_flag = 0;
			if (Pop_up_flag == 0)
				Display_page(pic_id_temp);
			else if (Pop_up_flag == 1)
			{

				Display_pop_up(Pop_up_id, Pop_up_x, Pop_up_y);
			}
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0xF1) // confirm
		{

			for (uint16_t j = 0; j < input_len; j++)
			{
				var[gAio_Info[Aio_num].p_add * 2 + j] = Display_buff[j];
			}

			var[gAio_Info[Aio_num].p_add * 2 + input_len] = 0x00;
			var[gAio_Info[Aio_num].p_add * 2 + input_len + 1] = 0x00;

			if (gAio_Info[Aio_num].Code == 0xC009)
			{
				rebuf[3] = 0x41;
				rebuf[4] = gAio_Info[Aio_num].p_add >> 8;
				rebuf[5] = gAio_Info[Aio_num].p_add & 0xFF;
				for (uint8_t j = 0; j < input_len; j++)
				{
					rebuf[6 + j] = var[gAio_Info[Aio_num].p_add * 2 + j];
				}
				if (input_len % 2 > 0)
				{
					rebuf[6 + input_len] = var[gAio_Info[Aio_num].p_add * 2 + input_len];
					LT_InfoFeedback_with_addr(rebuf, 3 + input_len + 1);
				}
				else
					LT_InfoFeedback_with_addr(rebuf, 3 + input_len);
			}

			if (Pop_up_flag == 0)
				Display_page(pic_id_temp);
			else if (Pop_up_flag == 1)
			{
				Display_pop_up(Pop_up_id, Pop_up_x, Pop_up_y);
			}
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0xF2) // backspace
		{
			if (input_len > 0)
			{
				Cusor_time = 0;
				input_len--;
			}
			else
			{
				Cusor_time = 0;
				input_len = 0;
			}

			Display_buff[input_len] = 0x00;

			LT_Print_zk_Font(4, gAio_Info[Aio_num].zk_addr,
							 LAY_BUFF1, LCD_XSIZE_TFT, gAio_Info[Aio_num].zk_w, gAio_Info[Aio_num].zk_h, 3, gAio_Info[Aio_num].fcolor, Black, 0, 1, PICINFO[0], gAio_Info[Aio_num].input_mode,
							 gAio_Info[Aio_num].dp_x + gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y,
							 PICINFO[0].x + PICINFO[0].w - 1, gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y + gAio_Info[Aio_num].zk_h - 1,
							 0, 0, Display_buff, input_len);

			input_w = data_w;
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0xF3) // Caps lock
		{
			if (CapsLock == 0)
				CapsLock = 1;
			else
				CapsLock = 0;
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0xF4)
		{
		}
		else if (gKb_Info[Kb_num].Keyvalue == 0xF5)
		{
			LT268_dispaly_CutPicture(gAio_Info[Aio_num].kb_x + gAio_Info[Aio_num].dp_x, gAio_Info[Aio_num].kb_y + gAio_Info[Aio_num].dp_y,
									 gAio_Info[Aio_num].dp_x, gAio_Info[Aio_num].dp_y, PICINFO[0].w - gAio_Info[Aio_num].dp_x, gAio_Info[Aio_num].zk_h,
									 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);

			memset(Display_buff, 0, input_len);
			input_len = 0;
			input_w = 0;
		}
		else // Normal key value
		{
			if (gAio_Info[Aio_num].p_len * 2 > input_len)
			{
				if (CapsLock == 1)
				{
					Display_buff[input_len] = (gKb_Info[Kb_num].Keyvalue >> 8) & 0xFF;
				}
				else
				{
					Display_buff[input_len] = gKb_Info[Kb_num].Keyvalue & 0xFF;
				}
				input_len++;
			}

			LT_Print_zk_Font(4, gAio_Info[Aio_num].zk_addr,
							 LAY_BUFF1, LCD_XSIZE_TFT, gAio_Info[Aio_num].zk_w, gAio_Info[Aio_num].zk_h, 3, gAio_Info[Aio_num].fcolor, Black, 0, 1, PICINFO[0], gAio_Info[Aio_num].input_mode,
							 gAio_Info[Aio_num].dp_x + gAio_Info[Aio_num].kb_x, gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y,
							 PICINFO[0].x + PICINFO[0].w - 1, gAio_Info[Aio_num].dp_y + gAio_Info[Aio_num].kb_y + gAio_Info[Aio_num].zk_h - 1,
							 0, 0, Display_buff, input_len);

			input_w = data_w;
		}
		Kb_flag = 0;
	}
}

/***********************************************************************************
 * Function Name : GBK_input
 * Description   : Touch detection of GBK keyboard.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void GBK_input(void)
{
	uint8_t res = 0;
	uint16_t i = 0, l = 0;
	uint8_t rebuf[50];
	uint8_t buff1[12] = {0};
	uint16_t k = 0;
	uint32_t zk_addr = 0;
	uint32_t color;

	// press down
	if (gTpInfo.sta && GBKioKb_flag == 0)
	{
		for (i = 0; i < GBKio_count; i++)
		{
			if (gTpInfo.x[0] >= gGBKio_Info[i].Xs && gTpInfo.y[0] >= gGBKio_Info[i].Ys &&
				gTpInfo.x[0] <= gGBKio_Info[i].Xe && gTpInfo.y[0] <= gGBKio_Info[i].Ye &&
				GBKio_flag == 0 && button_Press_flag == 0)
			{
				GBKio_num = i;
				GBKio_flag = 1;
				button_Press_flag = 1;
				if (buzzer)
					touch_buzzer();
			}
		}
	}
	if (Button_Key_Code_Flag == 1)
	{
		for (i = 0; i < GBKio_count; i++)
		{
			if (gGBKio_Info[i].Xs == 0xFFFF && gGBKio_Info[i].Ys ==  Button_Key_Code)
			{
				Button_Key_Code_Flag = 0;
				Button_Key_Code = 0;
				GBKio_num = i;
				GBKio_flag = 1;
				if (Pop_up_flag == 1) // pop-up window
				{
				}
				LT_ReadFlash_UI(buff1, addr_index[6] + 12 * gGBKio_Info[GBKio_num].kb_id, 12);
				pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
				pic_w = buff1[4] + (buff1[5] << 8);
				pic_h = buff1[6] + (buff1[7] << 8);
				pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
				pic_flag = buff1[11];

				// Record keyboard background information
				PICINFO[0].addr = pic_add;
				PICINFO[0].w = pic_w;
				PICINFO[0].h = pic_h;
				PICINFO[0].len = pic_len;
				PICINFO[0].flag = pic_flag;
				PICINFO[0].x = gGBKio_Info[GBKio_num].kb_x;
				PICINFO[0].y = gGBKio_Info[GBKio_num].kb_y;

				if (pic_len != 0 && pic_flag != 0xFF)
				{
					// display keyboard
					if (PICINFO[0].flag == 0 || PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
						LT_ShowPicture(PICINFO[0].x, PICINFO[0].y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr, pic_len, PICINFO[0].flag); 

				}

				/*Dynamic picture coverage judgment*/
				GBKioKb_flag = 1;
				gGBKio_Info[GBKio_num].Xs = gGBKio_Info[GBKio_num].kb_x;
				gGBKio_Info[GBKio_num].Ys = gGBKio_Info[GBKio_num].kb_y;
				gGBKio_Info[GBKio_num].Xe = gGBKio_Info[GBKio_num].kb_x + pic_w;
				gGBKio_Info[GBKio_num].Ye = gGBKio_Info[GBKio_num].kb_y + pic_h;

				LT_ReadFlash_UI(buff1, addr_index[2] + gGBKio_Info[GBKio_num].py_zk * 8, 4);
				gGBKio_Info[GBKio_num].py_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
				LT_ReadFlash_UI(buff1, addr_index[2] + gGBKio_Info[GBKio_num].zk_id * 8, 4);
				gGBKio_Info[GBKio_num].zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
				
				cur_x = gGBKio_Info[GBKio_num].dp_x + gGBKio_Info[GBKio_num].kb_x;
				cur_y = gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y;
				buff1[0] = '|';
				buff1[1] = 0;

				if (gGBKio_Info[GBKio_num].cursor_color == 0)
					color = Black;
				else
					color = White;

		//		cur_w = gGBKio_Info[GBKio_num].zk_w / 2;
				cur_w = gGBKio_Info[GBKio_num].zk_w;

				button_Press_flag = 0;
				input_len = 0;
				GBK_PY_length = 0;
				CapsLock = 0;
				GBK_CN_EN = 0;
				input_w = 0;
				memset(Display_buff, 0, sizeof(Display_buff));

				pic_id_temp = pic_id;
				pic_id = gGBKio_Info[GBKio_num].kb_id;

				if (gGBKio_Info[GBKio_num].scan_mode == 1)
				{
					for (k = 0; k < gGBKio_Info[GBKio_num].p_len * 2; k++)
					{

						Display_buff[k] = var[gGBKio_Info[GBKio_num].p_add * 2 + k];
						if (var[gGBKio_Info[GBKio_num].p_add * 2 + k] == 0x00 && var[gGBKio_Info[GBKio_num].p_add * 2 + k + 1] == 0x00)
							break;
					}
					input_len = k;

					// Display GBK font on keyboard
					LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
									 LAY_BUFF2, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, White, 0, 1, PICINFO[0], 0,
									 gGBKio_Info[GBKio_num].dp_x + gGBKio_Info[GBKio_num].kb_x, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y,
									 PICINFO[0].x + PICINFO[0].w - 1, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].zk_h - 1,
									 0, 0, Display_buff, input_len);

					input_w = data_w;
					
					LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
									 LAY_BUFF2, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, color, White, 0, 1, PICINFO[0], 0,
									 cur_x + input_w, cur_y, cur_x + input_w + cur_w + 1, cur_y + gGBKio_Info[GBKio_num].zk_h - 1, 
									 0, 0, buff1, 1);
					
				}
				else
				{
					LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
									 LAY_BUFF2, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, color, White, 0, 1, PICINFO[0], 0,
									 cur_x, cur_y, cur_x + cur_w + 1, cur_y + gGBKio_Info[GBKio_num].zk_h - 1, 
									 0, 0, buff1, 1);
				}

				Get_Touch_info(gGBKio_Info[GBKio_num].kb_id);
				GBKio_flag = 0;
				memset(GBK_PY_buff, 0, 6);
				Cusor_time = 0;
				break;
			}
		}
	}
	
	// raise
	if (gTpInfo.sta == 0 && GBKio_flag == 1 && GBKioKb_flag == 0)
	{
		if (Pop_up_flag == 1) // pop-up window
		{
		}

		LT_ReadFlash_UI(buff1, addr_index[6] + 12 * gGBKio_Info[GBKio_num].kb_id, 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		// Record keyboard background information
		PICINFO[0].addr = pic_add;
		PICINFO[0].w = pic_w;
		PICINFO[0].h = pic_h;
		PICINFO[0].len = pic_len;
		PICINFO[0].flag = pic_flag;
		PICINFO[0].x = gGBKio_Info[GBKio_num].kb_x;
		PICINFO[0].y = gGBKio_Info[GBKio_num].kb_y;

		if (pic_len != 0 && pic_flag != 0xFF)
		{
			// display keyboard
			if (PICINFO[0].flag == 0 || PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
				LT_ShowPicture(PICINFO[0].x, PICINFO[0].y, PICINFO[0].w, PICINFO[0].h, PICINFO[0].addr, pic_len, PICINFO[0].flag); 
		}

		/*Dynamic picture coverage judgment*/
		GBKioKb_flag = 1;
		gGBKio_Info[GBKio_num].Xs = gGBKio_Info[GBKio_num].kb_x;
		gGBKio_Info[GBKio_num].Ys = gGBKio_Info[GBKio_num].kb_y;
		gGBKio_Info[GBKio_num].Xe = gGBKio_Info[GBKio_num].kb_x + pic_w;
		gGBKio_Info[GBKio_num].Ye = gGBKio_Info[GBKio_num].kb_y + pic_h;

		LT_ReadFlash_UI(buff1, addr_index[2] + gGBKio_Info[GBKio_num].py_zk * 8, 4);
		gGBKio_Info[GBKio_num].py_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		LT_ReadFlash_UI(buff1, addr_index[2] + gGBKio_Info[GBKio_num].zk_id * 8, 4);
		gGBKio_Info[GBKio_num].zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		
		cur_x = gGBKio_Info[GBKio_num].dp_x + gGBKio_Info[GBKio_num].kb_x;
		cur_y = gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y;
		buff1[0] = '|';
		buff1[1] = 0;

		if (gGBKio_Info[GBKio_num].cursor_color == 0)
			color = Black;
		else
			color = White;

//		cur_w = gGBKio_Info[GBKio_num].zk_w / 2;
		cur_w = gGBKio_Info[GBKio_num].zk_w;

		button_Press_flag = 0;
		input_len = 0;
		GBK_PY_length = 0;
		CapsLock = 0;
		GBK_CN_EN = 0;
		input_w = 0;
		memset(Display_buff, 0, sizeof(Display_buff));

		pic_id_temp = pic_id;
		pic_id = gGBKio_Info[GBKio_num].kb_id;

		if (gGBKio_Info[GBKio_num].scan_mode == 1)
		{
			for (k = 0; k < gGBKio_Info[GBKio_num].p_len * 2; k++)
			{

				Display_buff[k] = var[gGBKio_Info[GBKio_num].p_add * 2 + k];
				if (var[gGBKio_Info[GBKio_num].p_add * 2 + k] == 0x00 && var[gGBKio_Info[GBKio_num].p_add * 2 + k + 1] == 0x00)
					break;
			}
			input_len = k;

			// Display GBK font on keyboard
			LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
							 LAY_BUFF2, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, White, 0, 1, PICINFO[0], 0,
							 gGBKio_Info[GBKio_num].dp_x + gGBKio_Info[GBKio_num].kb_x, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y,
							 PICINFO[0].x + PICINFO[0].w - 1, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].zk_h - 1,
							 0, 0, Display_buff, input_len);

			input_w = data_w;
			
			LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
							 LAY_BUFF2, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, color, White, 0, 1, PICINFO[0], 0,
							 cur_x + input_w, cur_y, cur_x + input_w + cur_w + 1, cur_y + gGBKio_Info[GBKio_num].zk_h - 1, 
							 0, 0, buff1, 1);
			
		}
		else
		{
			LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
							 LAY_BUFF2, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, color, White, 0, 1, PICINFO[0], 0,
							 cur_x, cur_y, cur_x + cur_w + 1, cur_y + gGBKio_Info[GBKio_num].zk_h - 1, 
							 0, 0, buff1, 1);
		}

		Get_Touch_info(gGBKio_Info[GBKio_num].kb_id);
		GBKio_flag = 0;
		memset(GBK_PY_buff, 0, 6);
		Cusor_time = 0;
	}

	// press down within the range of keyboard
	if (gTpInfo.sta && GBKioKb_flag == 1 && GBKio_flag == 0)
	{
		for (i = 0; i < Kb_count; i++)
		{
			if (gTpInfo.x[0] >= gKb_Info[i].Xs + gGBKio_Info[GBKio_num].kb_x && gTpInfo.y[0] >= gKb_Info[i].Ys + gGBKio_Info[GBKio_num].kb_y && gTpInfo.x[0] <= gKb_Info[i].Xe + gGBKio_Info[GBKio_num].kb_x && gTpInfo.y[0] <= gKb_Info[i].Ye + gGBKio_Info[GBKio_num].kb_y && Kb_flag == 0)
			{
				if (gKb_Info[i].press_id != 0xFFFF)
				{
					LT_ReadFlash_UI(buff1, addr_index[6] + 12 * gKb_Info[i].press_id, 12);
					pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
					pic_w = buff1[4] + (buff1[5] << 8);
					pic_h = buff1[6] + (buff1[7] << 8);
					pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
					pic_flag = buff1[11];

					LT268_dispaly_CutPicture(gGBKio_Info[GBKio_num].kb_x + gKb_Info[i].Xs, gGBKio_Info[GBKio_num].kb_y + gKb_Info[i].Ys,
											 gKb_Info[i].Xs, gKb_Info[i].Ys, gKb_Info[i].Xe - gKb_Info[i].Xs + 1, gKb_Info[i].Ye - gKb_Info[i].Ys + 1,
											 pic_w, pic_add, pic_len, pic_flag);
				}
				Kb_num = i;
				Kb_flag = 1;
				if (buzzer)
					touch_buzzer();
			}
		}

		if (GBK_PY_length > 0 && Kb_flag == 0 && GBK_PY_num > 0)
		{
			choice_GBK();
		}
	}

	// raise
	if (gTpInfo.sta == 0 && GBKioKb_flag == 1 && GBKio_flag == 0 && Kb_flag == 1)
	{
		LT_ReadFlash_UI(buff1, addr_index[6] + 12 * gGBKio_Info[GBKio_num].kb_id, 12);
		PICINFO[0].addr = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		PICINFO[0].w = buff1[4] + (buff1[5] << 8);
		PICINFO[0].h = buff1[6] + (buff1[7] << 8);
		PICINFO[0].len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		PICINFO[0].flag = buff1[11];
		PICINFO[0].x = gGBKio_Info[GBKio_num].kb_x;
		PICINFO[0].y = gGBKio_Info[GBKio_num].kb_y;

		if ((gKb_Info[Kb_num].press_id != 0xFFFF && gKb_Info[Kb_num].Keyvalue != 0xF3 && gKb_Info[Kb_num].Keyvalue != 0xF4) || (CapsLock == 1 && gKb_Info[Kb_num].Keyvalue == 0xF3) || (GBK_CN_EN == 1 && gKb_Info[Kb_num].Keyvalue == 0xF4))
		{
			LT268_dispaly_CutPicture(gGBKio_Info[GBKio_num].kb_x + gKb_Info[Kb_num].Xs, gGBKio_Info[GBKio_num].kb_y + gKb_Info[Kb_num].Ys,
									 gKb_Info[Kb_num].Xs, gKb_Info[Kb_num].Ys, gKb_Info[Kb_num].Xe - gKb_Info[Kb_num].Xs + 1, gKb_Info[Kb_num].Ye - gKb_Info[Kb_num].Ys + 1,
									 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);
		}

		if (GBK_PY_length == 0 && CapsLock == 1) // Pinyin is not entered and is in uppercase status
		{
			if (gKb_Info[Kb_num].Keyvalue == 0xF0) // cancel
			{
				GBKioKb_flag = 0;
				if (Pop_up_flag == 0)
					Display_page(pic_id_temp);
				else if (Pop_up_flag == 1)
				{
					Display_pop_up(Pop_up_id, Pop_up_x, Pop_up_y);
				}
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF1) // confirm
			{
				for (uint16_t j = 0; j < input_len; j++)
				{
					var[gGBKio_Info[GBKio_num].p_add * 2 + j] = Display_buff[j];
				}

				var[gGBKio_Info[GBKio_num].p_add * 2 + input_len] = 0x00;
				var[gGBKio_Info[GBKio_num].p_add * 2 + input_len + 1] = 0x00;

				if (gGBKio_Info[GBKio_num].Code == 0xC00A) // Serial port feedback
				{
					rebuf[3] = 0x41;
					rebuf[4] = gGBKio_Info[GBKio_num].p_add >> 8;
					rebuf[5] = gGBKio_Info[GBKio_num].p_add & 0xFF;

					if (input_len != 0)
					{
						for (uint16_t j = 0; j < input_len; j++)
						{
							rebuf[6 + j] = var[gGBKio_Info[GBKio_num].p_add * 2 + j];
						}
						if (input_len % 2 == 0)
							LT_InfoFeedback_with_addr(rebuf, 3 + input_len);
						else
						{
							rebuf[6 + input_len] = var[gGBKio_Info[GBKio_num].p_add * 2 + input_len];
							LT_InfoFeedback_with_addr(rebuf, 3 + input_len + 1);
						}
					}
					else if (input_len == 0)
					{
						rebuf[6] = 0x00;
						rebuf[7] = 0x00;
						LT_InfoFeedback_with_addr(rebuf, 5);
					}
				}
				if (Pop_up_flag == 0)
					Display_page(pic_id_temp);
				else if (Pop_up_flag == 1)
				{
					Display_pop_up(Pop_up_id, Pop_up_x, Pop_up_y);
				}
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF2) // backspace
			{
				if (input_len > 0)
				{
					for (l = 0; l < input_len;)
					{
						if (Display_buff[l] <= 0x7F)
						{
							l++;
							if (l == input_len)
							{
								Display_buff[input_len - 1] = 0x00;
								input_len--;
							}
						}
						else
						{
							l += 2;
							if (l == input_len)
							{
								Display_buff[input_len - 1] = 0x00;
								Display_buff[input_len - 2] = 0x00;
								input_len -= 2;
							}
						}
					}

					LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
									 LAY_BUFF1, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, Black, 0, 1, PICINFO[0], 0,
									 gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
									 PICINFO[0].x + PICINFO[0].w - 1, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].zk_h - 1,
									 0, 0, Display_buff, input_len);

					input_w = data_w;
				}
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF3) // Caps lock
			{
				if (CapsLock == 0)
					CapsLock = 1;
				else
					CapsLock = 0;
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF4) // Chinese and English input method switching
			{
				if (GBK_CN_EN == 0)
					GBK_CN_EN = 1;
				else
					GBK_CN_EN = 0; // Pinyin input
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF5) // clear display box of font
			{
				LT268_dispaly_CutPicture(gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
										 gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].dp_y, input_w, gGBKio_Info[GBKio_num].zk_h,
										 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);

				memset(Display_buff, 0, input_len);
				input_len = 0;
				input_w = 0;
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF7) // move
			{
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF8) // move
			{
			}
			else
			{
				if (gGBKio_Info[GBKio_num].p_len * 2 > input_len)
				{
					Display_buff[input_len] = (gKb_Info[Kb_num].Keyvalue >> 8) & 0xFF;
					input_len++;

					LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
									 LAY_BUFF1, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, Black, 0, 1, PICINFO[0], 0,
									 gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
									 PICINFO[0].x + PICINFO[0].w - 1, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].zk_h - 1,
									 0, 0, Display_buff, input_len);

					input_w = data_w;
				}
			}
		}
		else if (GBK_PY_length == 0 && GBK_CN_EN == 1) // English input, pinyin has not been input
		{
			if (gKb_Info[Kb_num].Keyvalue == 0xF0) // cancel
			{
				GBKioKb_flag = 0;
				Display_page(pic_id_temp);
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF1) // comfirm
			{
				for (uint16_t j = 0; j < input_len; j++)
				{
					var[gGBKio_Info[GBKio_num].p_add * 2 + j] = Display_buff[j];
				}

				var[gGBKio_Info[GBKio_num].p_add * 2 + input_len] = 0x00;
				var[gGBKio_Info[GBKio_num].p_add * 2 + input_len + 1] = 0x00;

				if (gGBKio_Info[GBKio_num].Code == 0xC00A) // Serial port feedback
				{
					rebuf[3] = 0x41;
					rebuf[4] = gGBKio_Info[GBKio_num].p_add >> 8;
					rebuf[5] = gGBKio_Info[GBKio_num].p_add & 0xFF;

					if (input_len != 0)
					{
						for (uint16_t j = 0; j < input_len; j++)
						{
							rebuf[6 + j] = var[gGBKio_Info[GBKio_num].p_add * 2 + j];
						}
						if (input_len % 2 == 0)
							LT_InfoFeedback_with_addr(rebuf, 3 + input_len);
						else
						{
							rebuf[6 + input_len] = var[gGBKio_Info[GBKio_num].p_add * 2 + input_len];
							LT_InfoFeedback_with_addr(rebuf, 3 + input_len + 1);
						}
					}
					else if (input_len == 0)
					{
						rebuf[6] = 0x00;
						rebuf[7] = 0x00;
						LT_InfoFeedback_with_addr(rebuf, 5);
					}
				}
				Display_page(pic_id_temp);
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF2) // backspace
			{

				if (input_len > 0)
				{
					for (l = 0; l < input_len;)
					{
						if (Display_buff[l] <= 0x7F)
						{
							l++;
							if (l == input_len)
							{
								Display_buff[input_len - 1] = 0x00;
								input_len--;
							}
						}
						else
						{
							l += 2;
							if (l == input_len)
							{
								Display_buff[input_len - 1] = 0x00;
								Display_buff[input_len - 2] = 0x00;
								input_len -= 2;
							}
						}
					}

					LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
									 LAY_BUFF1, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, Black, 0, 1, PICINFO[0], 0,
									 gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
									 PICINFO[0].x + PICINFO[0].w - 1, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].zk_h - 1,
									 0, 0, Display_buff, input_len);

					input_w = data_w;
				}
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF3) // Caps lock
			{
				if (CapsLock == 0)
					CapsLock = 1;
				else
					CapsLock = 0;
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF4) // Chinese and English input switching
			{
				GBK_CN_EN = 0; // Pinyin input
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF5) // clear display box of font
			{

				LT268_dispaly_CutPicture(gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
										 gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].dp_y, input_w, gGBKio_Info[GBKio_num].zk_h,
										 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);

				memset(Display_buff, 0, input_len);
				input_len = 0;
				input_w = 0;
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF7 || gKb_Info[Kb_num].Keyvalue == 0xF8) // move
			{
			}
			else
			{
				if (gGBKio_Info[GBKio_num].p_len * 2 > input_len)
				{
					Display_buff[input_len] = gKb_Info[Kb_num].Keyvalue & 0xFF;
					input_len++;

					LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
									 LAY_BUFF1, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, Black, 0, 1, PICINFO[0], 0,
									 gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
									 PICINFO[0].x + PICINFO[0].w - 1, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].zk_h - 1,
									 0, 0, Display_buff, input_len);

					input_w = data_w;
				}
			}
		}
		else // Pinyin input status
		{
			if (gKb_Info[Kb_num].Keyvalue == 0xF0) // cancel
			{
				GBKioKb_flag = 0;
				Display_page(pic_id_temp);
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF1) // comfirm
			{
				for (uint16_t j = 0; j < input_len; j++)
				{
					var[gGBKio_Info[GBKio_num].p_add * 2 + j] = Display_buff[j];
				}

				var[gGBKio_Info[GBKio_num].p_add * 2 + input_len] = 0x00;
				var[gGBKio_Info[GBKio_num].p_add * 2 + input_len + 1] = 0x00;

				if (gGBKio_Info[GBKio_num].Code == 0xC00A) // Serial port feedback
				{
					rebuf[3] = 0x41;
					rebuf[4] = gGBKio_Info[GBKio_num].p_add >> 8;
					rebuf[5] = gGBKio_Info[GBKio_num].p_add & 0xFF;

					if (input_len != 0)
					{
						for (uint16_t j = 0; j < input_len; j++)
						{
							rebuf[6 + j] = var[gGBKio_Info[GBKio_num].p_add * 2 + j];
						}
						if (input_len % 2 == 0)
							LT_InfoFeedback_with_addr(rebuf, 3 + input_len);
						else
						{
							rebuf[6 + input_len] = var[gGBKio_Info[GBKio_num].p_add * 2 + input_len];
							LT_InfoFeedback_with_addr(rebuf, 3 + input_len + 1);
						}
					}
					else if (input_len == 0)
					{
						rebuf[6] = 0x00;
						rebuf[7] = 0x00;
						LT_InfoFeedback_with_addr(rebuf, 5);
					}
				}
				Display_page(pic_id_temp);
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF2)
			{
				if (GBK_PY_length == 0)
				{
					if (input_len > 0)
					{
						for (l = 0; l < input_len;)
						{
							if (Display_buff[l] <= 0x7F)
							{
								l++;
								if (l == input_len)
								{
									Display_buff[input_len - 1] = 0x00;
									input_len--;
									break;
								}
							}
							else
							{
								l += 2;
								if (l == input_len)
								{
									Display_buff[input_len - 1] = 0x00;
									Display_buff[input_len - 2] = 0x00;
									input_len -= 2;
									break;
								}
							}
						}

						LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
										 LAY_BUFF1, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, Black, 0, 1, PICINFO[0], 0,
										 gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
										 PICINFO[0].x + PICINFO[0].w - 1, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].zk_h - 1,
										 0, 0, Display_buff, input_len);

						input_w = data_w;
					}
				}
				else if (GBK_PY_length > 0)
				{
					GBK_PY_length--;
					GBK_linenum = 0;
					GBK_PY_buff[GBK_PY_length] = 0x00;
					Display_PY_GBK();
				}
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF3) // Caps lock
			{
				if (CapsLock == 0)
					CapsLock = 1;
				else
					CapsLock = 0;
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF4) // English input
			{
				if (GBK_CN_EN == 0)
					GBK_CN_EN = 1;
				else
					GBK_CN_EN = 0; // Pinyin input
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF5) // clear display box of font
			{
				LT268_dispaly_CutPicture(gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
										 gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].dp_y, input_w, gGBKio_Info[GBKio_num].zk_h,
										 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);

				memset(Display_buff, 0, input_len);
				input_len = 0;
				input_w = 0;
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF7) // move
			{
				if (GBK_PY_length > 0)
				{
					if (GBK_linenum > 0)
						GBK_linenum--;
					Display_PY_GBK();
				}
			}
			else if (gKb_Info[Kb_num].Keyvalue == 0xF8)
			{
				GBK_linenum++;
				Display_PY_GBK();
			}
			else
			{
				if (GBK_PY_length == 0 && ((gKb_Info[Kb_num].Keyvalue & 0x00FF) > 122 || (gKb_Info[Kb_num].Keyvalue & 0x00FF) < 97))
				{
					if (gGBKio_Info[GBKio_num].p_len * 2 > input_len)
					{
						Display_buff[input_len] = gKb_Info[Kb_num].Keyvalue & 0xFF;
						input_len++;

						LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
										 LAY_BUFF1, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, Red, 0, 1, PICINFO[0], 0,
										 gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
										 gGBKio_Info[GBKio_num].kb_x + PICINFO[0].w - gGBKio_Info[GBKio_num].dp_x * 2, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].zk_h - 1,
										 0, 0, Display_buff, input_len);

						input_w = data_w;
					}
				}
				else
				{
					GBK_linenum = 0;
					if (CapsLock == 0) // Caps lock
					{
						if ((gKb_Info[Kb_num].Keyvalue & 0x00FF) != 0x00 && ((gKb_Info[Kb_num].Keyvalue & 0x00FF) <= 122 || (gKb_Info[Kb_num].Keyvalue & 0x00FF) >= 97))
						{
							if (GBK_PY_length == 0)
							{
								GBK_PY_buff[GBK_PY_length] = gKb_Info[Kb_num].Keyvalue & 0x00FF;
								GBK_PY_length++;
								Display_PY_GBK();
							}
							else if (GBK_PY_length < 6 && GBK_PY_num > 0)
							{
								GBK_PY_buff[GBK_PY_length] = gKb_Info[Kb_num].Keyvalue & 0x00FF;
								GBK_PY_length++;
								Display_PY_GBK();
							}
						}
					}
				}
			}
		}

		Kb_flag = 0;
	}

	if (gTpInfo.sta == 0 && GBKioKb_flag == 1 && GBKio_flag == 0 && Kb_flag == 2)
	{
		// select chinese
		LT268_dispaly_CutPicture(gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].py_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].py_y,
								 gGBKio_Info[GBKio_num].py_x, gGBKio_Info[GBKio_num].py_y, gGBKio_Info[GBKio_num].py_w * 6, gGBKio_Info[GBKio_num].py_h,
								 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);

		LT268_dispaly_CutPicture(gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].cn_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].cn_y,
								 gGBKio_Info[GBKio_num].cn_x, gGBKio_Info[GBKio_num].cn_y, (gGBKio_Info[GBKio_num].py_w + gGBKio_Info[GBKio_num].spacing) * 8, gGBKio_Info[GBKio_num].py_h,
								 PICINFO[0].w, PICINFO[0].addr, PICINFO[0].len, PICINFO[0].flag);

		LT_Print_zk_Font(1, gGBKio_Info[GBKio_num].zk_addr,
						 LAY_BUFF1, LCD_XSIZE_TFT, gGBKio_Info[GBKio_num].zk_w, gGBKio_Info[GBKio_num].zk_h, 3, gGBKio_Info[GBKio_num].fcolor, Black, 0, 1, PICINFO[0], 0,
						 gGBKio_Info[GBKio_num].kb_x + gGBKio_Info[GBKio_num].dp_x, gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].dp_y,
						 PICINFO[0].x + PICINFO[0].w - 1, gGBKio_Info[GBKio_num].dp_y + gGBKio_Info[GBKio_num].kb_y + gGBKio_Info[GBKio_num].zk_h - 1,
						 0, 0, Display_buff, input_len);

		input_w = data_w;
		Kb_flag = 0;
	}
}
void get_encoder(uint8_t type, uint8_t *buff, uint16_t addr)
{
	uint16_t i;
	uint16_t len, len1;

	len = buff[4] + (buff[5] << 8);
	len1 = 8;
	Check_box_add = buff[6] + (buff[7] << 8);

//	Var_AddrRemapping(&Check_box_add);

	for (i = 0; i <= 255; i++)
	{
		gEncoder_addr[i] = len1 + addr;
		len1 = len1 + buff[len1 + 1] + 2;
		if (len1 - 6 >= len)
			break;
	}

	gEncoderFlag = 1;

	gEncoder_num = (var[Check_box_add * 2] << 8) + var[Check_box_add * 2 + 1];
	if (gEncoder_num > i)
		gEncoder_num = i;
		
	gEncoder_count = i;
}
/***********************************************************************************
* Function Name : Display_encoder
* Description   : Run encoder.
* Input         : - type: encoder info sources
				  - buff: encoder info
* Output        : None
* Return        : None
************************************************************************************/
void Display_encoder(uint8_t *buff, uint8_t type)
{
	uint8_t i;
	uint8_t len, loop;
	int16_t sum = 0, V_max, V_min;
	uint16_t p_add = 0, step;
	uint8_t rebuf[50];
	uint16_t addr;

	len = buff[1];

	if (type == 4 || type == 0x84) // multi button control
	{
		for (i = 0; i < 32; i += 4)
		{
			addr = (buff[i + 2] + (buff[i + 2 + 1] << 8));
			Var_AddrRemapping(&addr);

			if (addr != 0xFFFF && addr <= VAR_ADDR_E)
			{
				var[addr * 2] = buff[i + 2 + 3];
				var[addr * 2 + 1] = buff[i + 2 + 2];
				
				if (addr >= VAR_ADDR_S)
				{
					reg_operation(addr);
				}
			}
		}
		if (type == 0x84)
		{
			rebuf[3] = 0x41;
			for (i = 0; i < 8; i++)
			{
				rebuf[4 * i + 4] = buff[4 * i + 2 + 1];
				rebuf[4 * i + 5] = buff[4 * i + 2];
				rebuf[4 * i + 6] = buff[4 * i + 2 + 3];
				rebuf[4 * i + 7] = buff[4 * i + 2 + 2];
			}
			LT_SendData_CRC_Frame(rebuf, 33);
		}

		if ((buff[0] + (buff[1] << 8)) < addr_index[7])
			Display_page(buff[0] + (buff[1] << 8));
		else
			page_date_update(pic_id);
		}
	else if (buff[0] == 1 || buff[0] == 0x81) // Multivariable control
	{
		for (i = 0; i < (len - 2); i += 4)
		{
			addr = (buff[i + 4] + (buff[i + 4 + 1] << 8));
			Var_AddrRemapping(&addr);
			if (addr != 0xFFFF && addr <= VAR_ADDR_E)
			{
				var[addr * 2] = buff[i + 4 + 3];
				var[addr * 2 + 1] = buff[i + 4 + 2];
				if (addr >= VAR_ADDR_S)
				{
					reg_operation(addr);
				}
			}
		}

		if (buff[0] == 0x81)
		{
			rebuf[3] = 0x41;
			for (i = 0; i < 8; i++)
			{
				rebuf[4 * i + 4] = buff[4 * i + 4 + 1];
				rebuf[4 * i + 5] = buff[4 * i + 4];
				rebuf[4 * i + 6] = buff[4 * i + 4 + 3];
				rebuf[4 * i + 7] = buff[4 * i + 4 + 2];
			}
			LT_SendData_CRC_Frame(rebuf, 33);
		}

		if ((buff[2] + (buff[3] << 8)) < addr_index[7])
			Display_page(buff[2] + (buff[3] << 8));
		else
			page_date_update(pic_id);
	}
	else if (buff[0] == 2 || buff[0] == 0x82)
	{
		p_add = buff[2] + (buff[3] << 8);
		V_max = buff[4] + (buff[5] << 8);
		V_min = buff[6] + (buff[7] << 8);
		step = buff[8] + (buff[9] << 8);
		loop = buff[11];
		
		Var_AddrRemapping(&p_add);
		
		sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
				
		if (buff[10] == 1) // ��
		{
			if (sum + step > V_max)
			{
				if (loop == 1) // ѭ��
				{
					var[p_add * 2] = V_min >> 8 & 0xFF;
					var[p_add * 2 + 1] = V_min & 0xFF;
				}
				else
				{
					var[p_add * 2] = V_max >> 8 & 0xFF;
					var[p_add * 2 + 1] = V_max & 0xFF;
				}
			}
			else
			{
				sum += step;
				var[p_add * 2] = sum >> 8 & 0xFF;
				var[p_add * 2 + 1] = sum & 0xFF;
			}
		}
		else if (buff[10] == 0) // ��
		{
			if (sum - step < V_min)
			{
				if (loop == 2)
				{
					var[p_add * 2] = V_max >> 8 & 0xFF;
					var[p_add * 2 + 1] = V_max & 0xFF;
				}
				else
				{
					var[p_add * 2] = V_min >> 8 & 0xFF;
					var[p_add * 2 + 1] = V_min & 0xFF;
				}
			}
			else
			{
				sum -= step;
				var[p_add * 2] = sum >> 8 & 0xFF;
				var[p_add * 2 + 1] = sum & 0xFF;
			}
		}
		if (buff[0] == 0x82)
		{
			rebuf[3] = 0x41;
			rebuf[4] = buff[3];
			rebuf[5] = buff[2];
			rebuf[6] = var[p_add * 2];
			rebuf[7] = var[p_add * 2 + 1];
			
			Var_AddrToReg(&rebuf[4]);
			
			LT_SendData_CRC_Frame(rebuf, 5);
		}
		if (p_add >= VAR_ADDR_S)
			reg_operation(p_add);

		page_date_update(pic_id);
	}
	else if (buff[0] == 3 || buff[0] == 0x83)
	{
		if (knob_flag == 0)
			knob_flag = 1;
		else if (knob_flag == 1)
			knob_flag = 0;
	}
///////////////////////////////////20240607
	//	if (pic_id == 2 || pic_id == 3)
	//	  knob_flag = 1;
	//	else if (pic_id == 0)//0
	//		knob_flag = 0;
	//	if (pic_id == 9)    //灯光免按下执行编码3
	//	  knob_flag = 1;
	//	else if (pic_id == 1)
	//		knob_flag = 0;
///////////////////////////////////
}



uint8_t knob_dir = 0, SW_flag = 0, SW_flag4 = 0, key_time = 0;
uint8_t Encoder_read_Flag = 0, Encoder_Freetime = 0;
uint8_t Enc0 = 0, Enc1 = 0;
uint8_t EncNow;
uint16_t Encoder_time = 0;
static uint8_t EncOld, EncX = 0;

uint8_t Double_click_interval = 0;
uint8_t Long_press = 0;
uint8_t Encoder_type = 0;

uint8_t pic_flag1,pic_flag2,pic_flag3,pic_flag6,pic_flag7,pic_flag9;
uint16_t pic_flagFM = 870;
uint8_t pic_flagDG = 1;
int pic_flagA = 1;  
int pic_flagB = 1;  
int pic_flagC = 1;
//uint8_t rebuf[9] = 0;
/***********************************************************************************
 * Function Name : encoder
 * Description   : Detect encoder rotation and key.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void encoder(void)
{
	uint16_t addr;
	uint16_t p_add, step;
	uint8_t type;
	uint8_t rebuf[10];
	int16_t V_max, V_min, sum = 0;

	if (Enc0 == 0)
		EncOld = (PINA ? 0x02 : 0x00) + (PINB ? 0x01 : 0x00); // Remember the status of the encoder at the first call
	if (EncOld == 0x00 || EncOld == 0x03)
		Enc0 = 1;

	// According to the current status of two IO, they are combined into a hexadecimal 0x00 | 0x01 | 0x02 | 0x03
	EncNow = (PINA ? 0x02 : 0x00) + (PINB ? 0x01 : 0x00);

	if ((EncOld == 0x00 && EncNow == 0x02) || (EncOld == 0x03 && EncNow == 0x01))
		EncX = EncNow; // 00-10|11-01

	// turn right,00-10-11|11-01-00
	if ((EncOld == 0x00 && EncX == 0x02 && EncNow == 0x03) || (EncOld == 0x03 && EncX == 0x01 && EncNow == 0x00))
	{
		Encoder_Freetime = 0;
		EncOld = EncNow, EncX = 0;
		Backlight_count = 0;
		if (var[VAR_BLAUTO * 2 + 1] ==1 && Backlight_flag == 0 )
		{
			Backlight_flag = 1;
			LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
		}
		else 
		{
			if(EncType == 1)
			{
				if (knob_flag == 1) // Move right at knob control variable to increase
				{
					addr = gEncoder_addr[gEncoder_num];
					p_add = config_buff[addr + 2] + (config_buff[addr + 3] << 8);
					
					Var_AddrRemapping(&p_add);

					sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
					V_max = config_buff[addr + 4] + (config_buff[addr + 5] << 8);
					V_min = config_buff[addr + 6] + (config_buff[addr + 7] << 8);
					step = config_buff[addr + 8] + (config_buff[addr + 9] << 8);


					if (sum + step > V_max)
					{
						var[p_add * 2] = V_max >> 8 & 0xFF;
						var[p_add * 2 + 1] = V_max & 0xFF;
					}
					else
					{
						sum += step;

						var[p_add * 2] = sum >> 8 & 0xFF;
						var[p_add * 2 + 1] = sum & 0xFF;
					}

					if (config_buff[addr] == 0x83)
					{
						rebuf[3] = 0x41;
						rebuf[4] = config_buff[addr + 3];
						rebuf[5] = config_buff[addr + 2];
						rebuf[6] = var[p_add * 2];
						rebuf[7] = var[p_add * 2 + 1];
						LT_SendData_CRC_Frame(rebuf, 5);
					}
				
					if (p_add >= VAR_ADDR_S)
						reg_operation(p_add);

					page_date_update(pic_id);

				}
				else
				{
					if (var[VAR_ENCODER_C * 2 + 1] == 1 && Gesture_flag == 1)
					{
						if (gGesture_Info.Code == 0xC000)
						{
							rebuf[3] = 0x41;
							rebuf[4] = 0xFF;
							rebuf[5] = 0xFF;
							rebuf[6] = (gGesture_Info.value[3] >> 8) & 0xFF;
							rebuf[7] = gGesture_Info.value[3] & 0xFF;
							LT_SendData_CRC_Frame(rebuf, 5);
						}
						Display_page(gGesture_Info.page[3]);
					}
					else
					{
						gEncoder_num++;
						if (gEncoder_num > gEncoder_count)
							gEncoder_num = 0;
						var[Check_box_add * 2] = (gEncoder_num >> 8) & 0xFF;
						var[Check_box_add * 2 + 1] = gEncoder_num & 0xFF;
						page_date_update(pic_id);
					}
				}
			}
			else
			{
				if (Enc1 == 0)
				{
					Enc1 = 1;
					knob_dir = 1;
					Encoder_Freetime = 0;
				}
				else
				{
					if (knob_dir == 1)
					{
						Enc1 = 0;
						knob_dir = 0;

						if (knob_flag == 1) // Move right at knob control variable to increase
						{
							addr = gEncoder_addr[gEncoder_num];
							p_add = config_buff[addr + 2] + (config_buff[addr + 3] << 8);
							
							Var_AddrRemapping(&p_add);

							sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
							V_max = config_buff[addr + 4] + (config_buff[addr + 5] << 8);
							V_min = config_buff[addr + 6] + (config_buff[addr + 7] << 8);
							step = config_buff[addr + 8] + (config_buff[addr + 9] << 8);
							
							if (sum + step > V_max)
							{
								var[p_add * 2] = V_max >> 8 & 0xFF;
								var[p_add * 2 + 1] = V_max & 0xFF;
							}
							else
							{
								sum += step;

								var[p_add * 2] = sum >> 8 & 0xFF;
								var[p_add * 2 + 1] = sum & 0xFF;
							}

							if (config_buff[addr] == 0x83)
							{
								rebuf[3] = 0x41;
								rebuf[4] = config_buff[addr + 3];
								rebuf[5] = config_buff[addr + 2];
								rebuf[6] = var[p_add * 2];
								rebuf[7] = var[p_add * 2 + 1];
								LT_SendData_CRC_Frame(rebuf, 5);
							}
						
							if (p_add >= VAR_ADDR_S)
								reg_operation(p_add);

							page_date_update(pic_id);

						}
						else
						{
							if (var[VAR_ENCODER_C * 2 + 1] == 1 && Gesture_flag == 1)
							{
								if (gGesture_Info.Code == 0xC000)
								{
									rebuf[3] = 0x41;
									rebuf[4] = 0xFF;
									rebuf[5] = 0xFF;
									rebuf[6] = (gGesture_Info.value[3] >> 8) & 0xFF;
									rebuf[7] = gGesture_Info.value[3] & 0xFF;
									LT_SendData_CRC_Frame(rebuf, 5);
								}
								Display_page(gGesture_Info.page[3]);
							}
							else
							{
								gEncoder_num++;
								if (gEncoder_num > gEncoder_count)
									gEncoder_num = 0;
								var[Check_box_add * 2] = (gEncoder_num >> 8) & 0xFF;
								var[Check_box_add * 2 + 1] = gEncoder_num & 0xFF;
								page_date_update(pic_id);
							}
						}
					}
					else
					{
						knob_dir = 1;
						Enc1 = 1;
					}
				}
			}
			
// ������4������ת
///////////////////////////////////���ƻ�////////////////////////////////////////////20240607   正

								if(pic_id == 0) 
								{
									pic_flagA++;
									if(pic_flagA > 4)
										pic_flagA = 1;
									
									var[0x010C*2] = pic_flagA>>8;
									var[0x010C*2+1] = pic_flagA&0xff;
									rebuf[0] = 0xAA;
									rebuf[1] = 0x01;
									rebuf[2] = pic_flagA&0xff;
									rebuf[3] = pic_flagB&0xff;
									rebuf[4] = pic_flagC&0xff;	
									//LT_SendData_CRC_Frame(rebuf, 5);
								}

								if(pic_id == 1) 
								{
									pic_flagB++;
									if(pic_flagB > 12)
										pic_flagB = 1;
									
									var[0x0116*2] = pic_flagB>>8;
			            var[0x0116*2+1] = pic_flagB&0xff;
									rebuf[0] = 0xAA;
									rebuf[1] = 0x02;
									rebuf[2] = pic_flagA&0xff;
									rebuf[3] = pic_flagB&0xff;
									rebuf[4] = pic_flagC&0xff;	
					        //LT_SendData_CRC_Frame(rebuf, 5);
								}
								if(pic_id == 2) 
								{
									pic_flagC++;
									if(pic_flagC > 12)
										pic_flagC = 1;
									
									var[0x0118*2] = pic_flagC>>8;
			            var[0x0118*2+1] = pic_flagC&0xff;
									rebuf[0] = 0xAA;
									rebuf[1] = 0x03;
									rebuf[2] = pic_flagA&0xff;
									rebuf[3] = pic_flagB&0xff;
									rebuf[4] = pic_flagC&0xff;	
					        //LT_SendData_CRC_Frame(rebuf, 5);
								}
									
								EFLASH_SetWritePermission();
								W_buff[1] = pic_flagA;
								W_buff[2] = pic_flagB;
								W_buff[3] = pic_flagC;
								EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
								EFLASH_ClrWritePermission();
								
								send500_time = 1;
///////////////////////////////////////////////////////////////////////////////
		}
	}

	if ((EncOld == 0x00 && EncNow == 0x01) || (EncOld == 0x03 && EncNow == 0x02))
		EncX = EncNow; // 00-01|11-10

	// turn left,00-01-11|11-10-00
	if ((EncOld == 0x00 && EncX == 0x01 && EncNow == 0x03) || (EncOld == 0x03 && EncX == 0x02 && EncNow == 0x00))
	{
		Encoder_Freetime = 0;
		EncOld = EncNow, EncX = 0;
		Backlight_count = 0;
		if (var[VAR_BLAUTO * 2 + 1] ==1 && Backlight_flag == 0)
		{			
			Backlight_flag = 1;
			LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
		}
		else 
		{
			if(EncType == 1)
			{
				if (knob_flag == 1) // At the knob control variable
				{
					addr = gEncoder_addr[gEncoder_num];
					p_add = config_buff[addr + 2] + (config_buff[addr + 3] << 8);
					
					Var_AddrRemapping(&p_add);
					
					sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
					V_max = config_buff[addr + 4] + (config_buff[addr + 5] << 8);
					V_min = config_buff[addr + 6] + (config_buff[addr + 7] << 8);
					step = config_buff[addr + 8] + (config_buff[addr + 9] << 8);
					

					if (sum - step < V_min)
					{
						var[p_add * 2] = V_min >> 8 & 0xFF;
						var[p_add * 2 + 1] = V_min & 0xFF;
					}
					else
					{
						sum -= step;
						var[p_add * 2] = sum >> 8 & 0xFF;
						var[p_add * 2 + 1] = sum & 0xFF;
					}
					if (config_buff[addr] == 0x83)
					{
						rebuf[3] = 0x41;
						rebuf[4] = config_buff[addr + 3];
						rebuf[5] = config_buff[addr + 2];
						rebuf[6] = var[p_add * 2];
						rebuf[7] = var[p_add * 2 + 1];
						LT_SendData_CRC_Frame(rebuf, 5);
					}
					if (p_add >= VAR_ADDR_S)
						reg_operation(p_add);

					page_date_update(pic_id);
				}
				else
				{
					if (var[VAR_ENCODER_C * 2 + 1] == 1 && Gesture_flag == 1)
					{
						if (gGesture_Info.Code == 0xC000)
						{
							rebuf[3] = 0x41;
							rebuf[4] = 0xFF;
							rebuf[5] = 0xFF;
							rebuf[6] = (gGesture_Info.value[3] >> 8) & 0xFF;
							rebuf[7] = gGesture_Info.value[3] & 0xFF;
							LT_SendData_CRC_Frame(rebuf, 5);
						}
						Display_page(gGesture_Info.page[2]);
					}
					else
					{
						if (gEncoder_num == 0)
							gEncoder_num = gEncoder_count;
						else
							gEncoder_num--;
						var[Check_box_add * 2] = (gEncoder_num >> 8) & 0xFF;
						var[Check_box_add * 2 + 1] = gEncoder_num & 0xFF;
						page_date_update(pic_id);
					}
				}
			}
			else
			{
				if (Enc1 == 0) // First rotation
				{
					knob_dir = 2;
					Enc1 = 1;
					Encoder_Freetime = 0;
				}
				else // Second rotation within 1S between the first rotation
				{
					if (knob_dir == 2)
					{
						Enc1 = 0;
						knob_dir = 0;
						if (knob_flag == 1) // At the knob control variable
						{
							addr = gEncoder_addr[gEncoder_num];
							p_add = config_buff[addr + 2] + (config_buff[addr + 3] << 8);
							
							Var_AddrRemapping(&p_add);
							
							sum = (var[p_add * 2] << 8) + var[p_add * 2 + 1];
							V_max = config_buff[addr + 4] + (config_buff[addr + 5] << 8);
							V_min = config_buff[addr + 6] + (config_buff[addr + 7] << 8);
							step = config_buff[addr + 8] + (config_buff[addr + 9] << 8);
							

							if (sum - step < V_min)
							{
								var[p_add * 2] = V_min >> 8 & 0xFF;
								var[p_add * 2 + 1] = V_min & 0xFF;
							}
							else
							{
								sum -= step;
								var[p_add * 2] = sum >> 8 & 0xFF;
								var[p_add * 2 + 1] = sum & 0xFF;
							}
							if (config_buff[addr] == 0x83)
							{
								rebuf[3] = 0x41;
								rebuf[4] = config_buff[addr + 3];
								rebuf[5] = config_buff[addr + 2];
								rebuf[6] = var[p_add * 2];
								rebuf[7] = var[p_add * 2 + 1];
								LT_SendData_CRC_Frame(rebuf, 5);
							}
							if (p_add >= VAR_ADDR_S)
								reg_operation(p_add);

							page_date_update(pic_id);
						}
						else
						{
							if (var[VAR_ENCODER_C * 2 + 1] == 1 && Gesture_flag == 1)
							{
								if (gGesture_Info.Code == 0xC000)
								{
									rebuf[3] = 0x41;
									rebuf[4] = 0xFF;
									rebuf[5] = 0xFF;
									rebuf[6] = (gGesture_Info.value[3] >> 8) & 0xFF;
									rebuf[7] = gGesture_Info.value[3] & 0xFF;
									LT_SendData_CRC_Frame(rebuf, 5);
								}
								Display_page(gGesture_Info.page[2]);
							}
							else
							{
								if (gEncoder_num == 0)
									gEncoder_num = gEncoder_count;
								else
									gEncoder_num--;
								var[Check_box_add * 2] = (gEncoder_num >> 8) & 0xFF;
								var[Check_box_add * 2 + 1] = gEncoder_num & 0xFF;
								page_date_update(pic_id);
							}
						}
					}
					else
					{
						knob_dir = 2;
						Enc1 = 1;
					}
				}
			}
			
// ������4������ת
///////////////////////////////////���ƻ�////////////////////////////////////////////20240607     反
								//DelayMS(5000);
								if(pic_id == 0) 
								{
									pic_flagA--;
							    if(pic_flagA < 1)
										pic_flagA = 4;
									
									var[0x010C*2] = pic_flagA>>8;
									var[0x010C*2+1] = pic_flagA&0xff;
									rebuf[0] = 0xAA;
									rebuf[1] = 0x01;
									rebuf[2] = pic_flagA&0xff;
									rebuf[3] = pic_flagB&0xff;
									rebuf[4] = pic_flagC&0xff;	
									//LT_SendData_CRC_Frame(rebuf, 5);
								}		

								if(pic_id == 1) 
								{
									pic_flagB--;
							    if(pic_flagB < 1)
										pic_flagB = 12;
									
                  var[0x0116*2] = pic_flagB>>8;
			            var[0x0116*2+1] = pic_flagB&0xff;
									rebuf[0] = 0xAA;
									rebuf[1] = 0x02;
									rebuf[2] = pic_flagA&0xff;
									rebuf[3] = pic_flagB&0xff;
									rebuf[4] = pic_flagC&0xff;		
					        //LT_SendData_CRC_Frame(rebuf, 5);
								}

								if(pic_id == 2) 
								{
									pic_flagC--;
									if(pic_flagC  < 1)
										pic_flagC = 12;
									
									var[0x0118*2] = pic_flagC>>8;
			            var[0x0118*2+1] = pic_flagC&0xff;
									rebuf[0] = 0xAA;
									rebuf[1] = 0x03;
									rebuf[2] = pic_flagA&0xff;
									rebuf[3] = pic_flagB&0xff;
									rebuf[4] = pic_flagC&0xff;	
					        //LT_SendData_CRC_Frame(rebuf, 5);
								}					
								
								EFLASH_SetWritePermission();
								W_buff[1] = pic_flagA;
								W_buff[2] = pic_flagB;
								W_buff[3] = pic_flagC;
								EFLASH_Write(flh_sAddr, &W_buff[0], WR_SIZE);	
								EFLASH_ClrWritePermission();
								
								send500_time = 1;
///////////////////////////////////////////////////////////////////////////////
		}
	}
	
/////////////////////////////20240607
/*	if(pic_encoder_page == 2)
	{
		SW_flag = 1;
		pic_encoder_page = 0;
	}
	if(pic_encoder_page == 3)
	{
		SW_flag = 1;
		pic_encoder_page = 0;
	}
	if(pic_encoder_page == 6)
	{
		SW_flag4 = 1;
		SW_flag = 2;
		pic_encoder_page = 0;
	}
	if(pic_encoder_page == 9)
	{
		SW_flag = 1;
		pic_encoder_page = 1;
	}*/
/////////////////////////////

	if(SW_flag)
	{
		Backlight_count = 0;
		if (var[VAR_BLAUTO * 2 + 1] ==1 && Backlight_flag == 0)
		{			
			SW_flag = 0;
			SW_flag4 = 0;
			Backlight_flag = 1;
			LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]);
		}
		else if (var[VAR_ENCODER_C * 2 + 1] == 1 && Gesture_flag == 1)
		{
			var[VAR_ENCODER_C * 2 + 1] = 0;
			SW_flag = 0;
			SW_flag4 = 0;
		}
		else
		{
			if (SW_flag == 1)
			{
///////////////////////////////20240607
				/*if(pic_id == 9)  ////////////灯光返回
				{
					//printf("1111111111111111111111222\r\n");
					pic_flag1++;
					if(pic_flag1 == 1)
					{
						Display_page(1);///6识别为1
						pic_flag9 = 0;
					}
				}*/


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
				SW_flag = 0;
				Enc1 = 0;
				knob_dir = 0;
				Display_encoder(&config_buff[gEncoder_addr[gEncoder_num]], 0);
			}
			else if (SW_flag4 == 3 && SW_flag == 4) //长
			{
				/*if(pic_id == 0) 
				{
					pic_flag3++;
 				 if(pic_flag3 == 1)
					{
					Display_Icon(30, 123, 58, 0);		
					printf("6666666666666666666666666666666666666666\r\n");
					rebuf[3] = 0x41;
					rebuf[4] = 0x01;
					rebuf[5] = 0x09;
					rebuf[6] = 0xC8;
					rebuf[7] = 0xD9;
					rebuf[8] = 0x81;
					LT_SendData_CRC_Frame(rebuf, 6);
					pic_flag3 = 0;
					}
				}*/
				SW_flag = 0;
				Enc1 = 0;
				knob_dir = 0;
				if ((config_buff[gEncoder_addr[gEncoder_num]] & 0x2F) == 0x24)
					type = 0x84;
				else
					type = 4;
				Display_encoder(&config_buff[gEncoder_addr[gEncoder_num] + 72], type);
			}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
			else if (SW_flag4 == 2 && SW_flag == 3)//双
			{
				/*if(pic_id == 0)  
				{
					pic_flag3++;
					if(pic_flag3 == 1)
					{
					rebuf[3] = 0x41;
					rebuf[4] = 0x00;
					rebuf[5] = 0x08;
					rebuf[6] = 0xC8;
					rebuf[7] = 0xD8;
					rebuf[8] = 0x81;
					LT_SendData_CRC_Frame(rebuf, 6);
					}
				 if(pic_flag3 == 2)
					{
					rebuf[3] = 0x41;
					rebuf[4] = 0x01;
					rebuf[5] = 0x08;
					rebuf[6] = 0xC8;
					rebuf[7] = 0xD8;
					rebuf[8] = 0x81;
					LT_SendData_CRC_Frame(rebuf, 6);
					pic_flag3 = 0;
					}
				}*/
				SW_flag = 0;
				Enc1 = 0;
				knob_dir = 0;
				if ((config_buff[gEncoder_addr[gEncoder_num]] & 0x4F) == 0x44)
					type = 0x84;
				else
					type = 4;
				Display_encoder(&config_buff[gEncoder_addr[gEncoder_num] + 37], type);
			}
			else if (SW_flag4 == 1 && SW_flag == 2)//单
			{
				//printf("333333333333333333333333333333333333\r\n");
/////////////////////////////////////20240607  按下执行当前
					//Display_Icon(77, 48, 8, 0);
					//Display_page(49);

			/*	if(pic_id == 0||pic_id == 1)
				{
					pic_flag3++;
				if(pic_flag3 == 1)
					{
					var[0x00B2*2] = 0x00;
			     var[0x00B2*2+1] = 0x00;
					//var[0x020E*2] = 0x00;
			    //var[0x020E*2+1] = 0x02;						
					rebuf[0] = 0x40;
					rebuf[1] = 0x8E;
					rebuf[2] = 0xC0;	
					LT_SendData_CRC_Frame(rebuf, 3);
					pic_flag3 = 0;
					}
						
				if(pic_flag3 == 2)
					{
					var[0x00B2*2] = 0x00;
			    var[0x00B2*2+1] = pic_flagA;	
					//var[0x020E*2] = 0x00;
			   // var[0x020E*2+1] = 0x00;												
					rebuf[0] = 0x40;
					rebuf[1] = 0x8E;
					rebuf[2] = 0xC1;	
					LT_SendData_CRC_Frame(rebuf, 3);
					pic_flag3 = 0;
					}
				}	
				if(pic_id == 2)
				{
					pic_flag3++;
				if(pic_flag3 == 1)
					{
					var[0x00B2*2] = 0x00;
			    var[0x00B2*2+1] = pic_flagA;	
					//var[0x020E*2] = 0x00;
			    //var[0x020E*2+1] = 0x02;						
					rebuf[0] = 0x40;
					rebuf[1] = 0x8E;
					rebuf[2] = 0xC1;	
					LT_SendData_CRC_Frame(rebuf, 3);
					pic_flag3 = 0;
					}
				}*/
				//page_date_update(pic_id);
/////////////////////////////////////////////
				SW_flag4 = 0;
				SW_flag = 0;
				Enc1 = 0;
				knob_dir = 0;
				if ((config_buff[gEncoder_addr[gEncoder_num]] & 0x8F) == 0x84)
					type = 0x84;
				else
					type = 4;
				Display_encoder(&config_buff[gEncoder_addr[gEncoder_num] + 2], type);
			}
		}
	}
	if (SW_flag4 == 2 || SW_flag4 == 3)
	{
		Backlight_count = 0;
		if (Read_Encoder_key == 1)
		{
			SW_flag4 = 0;
			Encoder_read_Flag = 0;
			Encoder_time = 0;
			key_time = 0;
		}
	}
}

/***********************************************************************************
 * Function Name : BackLight_control
 * Description   : Automatically adjust backlight.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void BackLight_control(void)
{
//#if (LT_TOUCH_FLAG == 1 || LT_TOUCH_FLAG == 2)
	if (Backlight_flag == 1)
	{
		if(Backlight_touch)
		{
			if(First_press == 1)
			{
				gTpInfo.sta = 0;   
				Backlight_count = 0;
				Backlight_flag = 1;       // disable touch function
			}
			else
			{
				gTpInfo.sta = 0;
				Backlight_count = 0;
				Backlight_flag = 1;
				Backlight_touch = 0;      // enable touch function     
			}
		}
		
		if (gTpInfo.sta == 1) // count reset
		{
			Backlight_count = 0;
			Backlight_flag = 1;
			Backlight_touch = 0;
		}
		else if (Backlight_count >= ((var[VAR_BLDURATION * 2] << 8) + var[VAR_BLDURATION * 2 + 1 ]) * 100) 
		{
			LT_BacklightSet(gDutyBuf[var[VAR_BLSLEEP * 2 + 1]]);  // sleep

			Backlight_count = 0;
			Backlight_flag = 0;
		}
	}
	else if (Backlight_flag == 0 && gTpInfo.sta == 1)
	{
		if (buzzer)
			touch_buzzer();
		gTpInfo.sta = 0;
		Backlight_touch = 1;
		Backlight_count = 0;
		Backlight_flag = 1;
		LT_BacklightSet(gDutyBuf[var[VAR_BL * 2 + 1]]); // operation
	}
//#endif
	


}


uint8_t lt_screen_dir = 0;
void LT_LCD_screen_dir(uint8_t dir)
{
//	LT_BacklightClose();	// backlight close
	
	
	LT_LCD_init_dir(dir);
	lt_screen_dir = dir;               //
	
	Address_Index();	//��ַ����
	
	if(GBKioKb_flag == 1 || DioKb_flag == 1 || AioKb_flag == 1)
	{
		if (Pop_up_flag == 0)
			Display_page(pic_id_temp);
		else if (Pop_up_flag == 1)
		{
			Pop_up_flag = 0;
			pic_id = (var[VAR_PAGE*2]<<8) + var[VAR_PAGE*2+1];
			Display_page(pic_id);    // pic_id
			Pop_up_flag = 1;
			Display_pop_up(Pop_up_id, Pop_up_x, Pop_up_y);
		}
	}
	else if(Pop_up_flag)	             // ��������,GIF�����¿�ʼ������?
	{
//		Display_page(pic_id);    // pic_id
		Pop_up_flag = 0;
		pic_id = (var[VAR_PAGE*2]<<8) + var[VAR_PAGE*2+1];
		Display_page(pic_id);    // pic_id
		Pop_up_flag = 1;
		Display_pop_up(Pop_up_id,Pop_up_x,Pop_up_y);
	}
	else
		Display_page(pic_id);
	

	LT_BacklightOpen(); 	// backlight open
}

void LT_TP_dir(void)
{
	uint16_t tempx=gTpInfo.x[0], tempy=gTpInfo.y[0];
	if(lt_screen_dir==0)
	{
//		gTpInfo.x[0] = tempy;
//		gTpInfo.y[0] = LCD_YSIZE_TFT - tempx;
	}
	else if(lt_screen_dir==1)
	{
		gTpInfo.x[0] = tempy;
		gTpInfo.y[0] = LCD_YSIZE_TFT - tempx;
	}
	else if(lt_screen_dir==2)
	{
		gTpInfo.x[0] = LCD_XSIZE_TFT - tempx;
		gTpInfo.y[0] = LCD_YSIZE_TFT - tempy;
	}
	else if(lt_screen_dir==3)
	{
		gTpInfo.x[0] = LCD_XSIZE_TFT - tempy;
		gTpInfo.y[0] = tempx;
	}
}

void LT_LCD_init_dir(uint8_t dir)
{
	/*screen init*/
//	LCD_TFT_Init();
	
//	TFT_CommandWrite(0x36); // reference: 0=0x00 1=0x60  2=0xC0 3=0xA0
//	if(dir==0)		TFT_DataWrite(0x00); // 0��
//	else if(dir==1)	TFT_DataWrite(0x60); // 90��
//	else if(dir==2)	TFT_DataWrite(0xC0); // 180��
//	else if(dir==3)	TFT_DataWrite(0xA0); // 270��

	if(dir!=lt_screen_dir)
	{
		
		TFT_CommandWrite(0x36);    // reference: 0=0x00 1=0x60  2=0xC0 3=0xA0
		if(dir==0)		TFT_DataWrite(0xC0); // 0��
		else if(dir==1)	TFT_DataWrite(0xA0); // 90��
		else if(dir==2)	TFT_DataWrite(0x00); // 180��
		else if(dir==3)	TFT_DataWrite(0x60); // 270��
		
		uint16_t w = LCD_XSIZE_TFT;
		if((dir==0 || dir==2) && (lt_screen_dir!=0) && (lt_screen_dir!=2))
		{
			LCD_XSIZE_TFT = LCD_YSIZE_TFT;
			LCD_YSIZE_TFT = w;
		}
		else if((dir==1 || dir==3) && (lt_screen_dir!=1) && (lt_screen_dir!=3))
		{
			LCD_XSIZE_TFT = LCD_YSIZE_TFT;
			LCD_YSIZE_TFT = w;
		}
	}

}

/**********/
#include "reset_drv.h"
#include "common.h"
typedef void (*iapfun)(void); // Define parameters of a function type.
extern iapfun jump2app;

#define Run_Boot_ID			(*(volatile uint32_t *)(0x20000000+0x37000))	//APP_Update_ID0: 0x32021688
	
#define APP_Update_ID0			(*(volatile uint32_t *)(0x20000000+0x28000))	//APP_Update_ID0: 0x32021688
#define APP_Update_ID1			(*(volatile uint32_t *)(0x20000000+0x28004))	//APP_Update_ID1: 0x19714568
void APP_reset(uint32_t appxaddr)
{
//	Run_Boot_ID = 0x47210659;
	
	APP_Update_ID0 = 0x32021688;
	APP_Update_ID1 = 0x19714568;

	LCD_BL_Init(gDutyBuf[0]);
	DelayMS(200);

	Disable_Interrupts;
//	Soft_Reset();	
	
  jump2app=(iapfun)*(vu32*)(appxaddr + 4); 
  jump2app();	
}